The future of German Chancellor Angela Merkel's coalition has been thrown into doubt after her deputy chancellor lost the leadership race of his party.
Olaf Scholz, who is also finance minister, lost his bid to become leader of the centre-left SPD.
The party is now expected to vote on whether to stay in the coalition with Ms Merkel's conservative CDU/CSU.
Mr Scholz's joint challengers, Norbert Walter-Borjans and Saskia Esken, have been highly critical of the coalition.
Elsewhere on Saturday, the far-right AfD, which is the biggest opposition party in the German parliament, elected Tino Chrupalla, a lawmaker from eastern Germany, to lead the party along with Joerg Meuthen.
What happened in the vote?
Mr Scholz and his running mate Klara Geywitz, who back staying in the coalition until 2021, received just 45.3% of the vote, while their challengers won 53%.
Mr Walter-Borjans and Ms Esken, relative unknowns from the party's leftist contingent, have said they want to renegotiate the coalition deal with Ms Merkel's conservatives to focus more on social justice and investment.
Mr Scholz said the SPD must now "stand behind the new leadership".
Paul Ziemiak, general secretary of the CDU (whose Bavarian sister party is the CSU), said "the decision today has changed nothing" about the alliance.
Poor election results and mixed views of Annegret Kramp-Karrenbauer, who replaced Ms Merkel as CDU leader in 2018, have led to discontent within the party.
Some have said a snap election or a minority government could be on the cards. Mrs Merkel has said she will not run again in 2021 after 14 years at the helm of the country.
Last week, Ms Kramp-Karrenbauer called for unity while threatening to stand down as CDU leader if the party failed to back her, which prompted a lengthy ovation at the annual congress.
Who is the AfD's new leader?
Mr Chrupalla is a former painter and decorator from Saxony.
He replaces one of the party's founders, 78-year-old Alexander Gauland, who gained international attention for a series of controversial remarks, including one comparing the Nazi era to a speck of bird droppings on German history.
"If we want more success we need to change," Mr Chrupalla said. "We want to move toward the centre. This will work because the CDU keeps moving to the left."
Joerg Meuthen was re-elected joint leader of the far-right party.