In theory, Merkel's coalition had more than enough votes in an assembly of lawmakers and public figures on Wednesday to comfortably secure an election of the conservative Christian Wulff to the largely ceremonial job of head of state.
But in dramatic scenes in what Berlin daily Der Tagesspiegel daily called the "day of the long knives," enough of her three-party coalition rebelled for Wulff to fall short of an absolute majority in two rounds of voting by secret ballot.
Wulff, 51, Lower Saxony's conservative state premier for seven years, was eventually elected in a third round but it took the longest-ever presidential election process in post-war German history to do so.
After the first two embarrassing voting rounds, the nail-biting third became a battle for the political future of Merkel, four times named the world's most powerful woman by Forbes Magazine.
A recent poll in mass-circulation daily Bild showed 48 percent of Germans wanted her to throw in the towel if her man had lost the vote, compared to 30 percent who believed she should soldier on.
Despite being hand-picked by Merkel, Wulff faced a strong challenge from Joachim Gauck, 70, a former East German dissident and pastor, who polls showed was more popular among ordinary voters.
Bild called the election a "massive slap" for Merkel while the centre-left weekly Die Zeit said it was a "humiliation" nine months after she won a second term at the head of Europe's biggest economy.
Business daily Handelsblatt described the "debacle" as Merkel's "first vote of no confidence."
Der Spiegel magazine said it was her "biggest failure."
With hundreds of people watching events unfold on huge screens outside parliament, Merkel was reduced before the third round to making a last-ditch "heartfelt request" and employing a World Cup football analogy.
"We have had the Serbia game. Now we've got the England game. Let's do the right thing," Merkel said, according to Bild. Germany lost 1-0 to Serbia but bounced back to hammer England 4-1 in this summer's World Cup.
"The coalition has clearly failed to give a show of unity and of the new start so badly needed to escape from the slump it has been in for weeks," said political scientist Oskar Niedermayer from Berlin's Free University.
Guido Westerwelle, head of Merkel's junior coalition partners the Free Democrats, declined to comment afterwards on how many members of his party had voted against Wulff.
"What counts is that we have a president in the third round with an absolute majority and with a clear lead over his challengers," Westerwelle told rolling news channel N-TV.
The headache of finding a new president was foisted upon Merkel by the surprise resignation of president Horst Köhler on May 31 after he appeared to suggest German troops abroad were defending Berlin's economic interests.
The fiasco caps a rough few months for Merkel, 55, after she won a second term at the helm of Europe's top economy in September with a new-look coalition more to her liking than her CDU's previous tie-up with the Social Democrats.
She has seen her popularity nosedive over her handling of the eurozone crisis and has come under fire for plans to slash government spending by more than €80 billion over the next four years.
The Süddeutsche Zeitung daily said "a shadow is now hanging over Angela Merkel."