The man behind Murphy's law probably never said "anything that can go wrong will go wrong." And the idea was old long before he was born.
The name comes from Edward A. Murphy Jr., an American engineer. Around 1948 and 1949 he worked on Project MX981 at Muroc Army Air Field in California. The project, led by John Paul Stapp, used rocket sleds to test how much deceleration a person could survive.
Murphy supplied sensors to measure the forces. In the best-known account, they failed because they had been wired incorrectly. What happened next depends on who is telling it. George Nichols, an engineer on the project, recalled Murphy blaming a technician with the line "If that guy has any way of making a mistake, he will." In Nichols's version, the team named the principle "Murphy's law" partly to tease him.
Murphy's son Robert disputed that account. He said his father's point was about design: if one way of doing a job leads to disaster, someone will eventually do it that way. Read like that, the law is a warning to engineers, not a shrug at bad luck. Stapp used the law in a similar spirit. At a press conference, he credited the team's good safety record to their belief in Murphy's law.
The first known appearance in print is in Anne Roe's 1952 book The Making of a Scientist. A physicist she interviewed called it "Murphy's law or the fourth law of thermodynamics." That suggests the name was already circulating among scientists by then. The Phrase Finder notes a rival claim: John Glenn wrote in 1962 that Murphy was a careless mechanic in Navy training cartoons. That version is less well supported.
What is clear is that the sentiment is not Murphy's invention. In 1866 the mathematician Augustus De Morgan wrote that "whatever can happen will happen if we make trials enough." In 1877 Alfred Holt told a meeting of engineers that anything that can go wrong at sea generally does. In 1908 the stage magician Nevil Maskelyne wrote that on a big occasion, "everything that can go wrong will go wrong."
So Murphy lent his name, not the idea. The law stuck to him because it had a catchy owner, a dramatic setting and a colonel willing to repeat it to reporters.