IRStuff: what I've advocated is that the OP determine which job is better for them AND for the prospective employer, based on their own values, and leave the issue of which offer came in first aside from the discussion. I cannot decide for someone which is more important: their interest in the type of work, the pay, other benefits, the opportunity for growth or advancement, or their feeling of duty or honour in making an agreement- each person values these things differently.
If the business reason for the job position disappears, the firm making the 1st offer can and likely will cancel the offer and give the OP NO COMPENSATION to the prospective candidate. You may consider that harsh and ungenteel, but it's business reality. Given this fact, a firm cannot expect someone who has accepted an offer of employment to treat this offer as if it were a contract, nor can they expect compensation from the candidate who accepted and then withdrew their acceptance, for the cost of going back to the marketplace to find another candidate.
Do I feel that my first employer dealt with me shabbily? Yes, but they could have been worse still and simply withdrawn the position entirely, leaving me far worse off. Would I do the same to a prospective employee? I don't know how willing I'd be to take a pay cut to pay the salary of an unemployed and now-unnecessary employee simply because some months earlier the firm had agreed to hire him or her. Now if this person had left gainful employ elsewhere to take this offered position, there might be a legal case for compensation- I don't know, you'd need to consult a lawyer on that one.
Frankly I consider myself to be at fault as well: I was young and naive and had an idealistic and inaccurate view of the employer/employee relationship and the nature of an agreement.
If candidates and firms want to have contractual rights, money has to change hands to generate a cost to either party of withdrawing from the agreement. Only then can it be considered a contract. Not only does that make legal sense to me, it makes ethical sense as well.
Frankly I share MechEng2005's opinion. I get quite sick of being preached to by people who seem to think that the ethical responsibilities of a professional engineer require them to allow their employers to treat them as doormats, or to treat the employer/employee business relationship as anything other than what it is. Frankly it's this point of view that has done much damage to the position of the engineering profession relative to that of other professions over the years in my estimation. There is a HUGE difference between holding the public safety as paramount even if that means losing your job, and withdrawing from a non-contractual business agreement later found to be unsatisfactory. One of the ethical obligations of a professional engineer is to openly take just compensation for their work, and to uphold the principle of fair compensation for engineering work, and that responsibility is one that I see far too many professional engineers taking less than seriously.