German Chancellor Angela Merkel's candidate has failed to win an absolute majority in the second round of the presidential election at the Reichstag.
Christian Wulff is nevertheless thought likely to win a third round shortly as he now only needs a simple majority.
Rebel votes in the ruling centre-right coalition twice deprived him of an outright win against challenger Joachim Gauck, an ex-East German pastor.
That the vote has gone to a third round is seen as embarrassing for Mrs Merkel.
Although the role of president is largely symbolic, the BBC's Steve Rosenberg in Berlin says a win for Mr Gauck would be a disaster for the embattled Mrs Merkel.
'Day of long knives'
She is under increasing pressure over her government's package of austerity measures and because of infighting in the cabinet, our correspondent says.
In the second round, Mr Wulff fell eight votes short of an absolute majority.
In the first round, the Lower Saxony state governor and deputy leader of Mrs Merkel's Christian Democratic Party was 23 ballots short.
A total of 1,244 elected representatives take part in the secret ballot of the electoral college. Half are federal legislators and half state-parliament nominees.
Mrs Merkel's ruling coalition has 644 seats in the special assembly, well over the 623 needed for an absolute majority.
But in the first round Mr Wulff could only muster 600 votes to Mr Gauck's 499.
Mr Wulff secured 615 votes in the second ballot, and Mr Gauck gained 490.
The results indicate a few delegates from Mrs Merkel's camp either voted against Mr Wulff or abstained.
Lukrezia Jochimsen, from the far-left Die Linke party, was a distant third in both votes.
Mass-circulation daily Bild said the result was a "massive slap" for Mrs Merkel, while the centre-left Die Zeit said it was a "humiliation".
The Tagesspiegel newspaper called it the "day of the long knives", and business daily Handelsblatt described it as Mrs Merkel's "first vote of no confidence".
'Message to Merkel'
"It is more exciting than anyone expected. It looks like a lot of people wanted to send Merkel a message," said Frank-Walter Steinmeier, parliamentary leader of the opposition centre-left Social Democrats, reports news agency Reuters.
Our correspondent says Mr Gauck is popular and widely respected; he is a non-partisan human rights campaigner who did much to expose the crimes of the East German secret police, the Stasi.
Since coming to power last October, Mrs Merkel's coalition has had to tackle the eurozone debt crisis.
This has led to European partners being granted rescue packages, which have been deeply unpopular in Germany.
Mrs Merkel and her main coalition ally Guido Westerwelle, of the Free Democrats, have endured weeks of negative publicity.
The presidential election was called after Horst Koehler stepped down on 31 May.
He stood down amid criticism after he appeared to suggest German troops abroad were defending Berlin's economic interests.