A former Lutheran pastor and civil rights activist has been elected as Germany’s new president.
Joachim Gauck, from the former East Germany, won 991 votes out of 1,232 at a special assembly of MPs.
The 72-year-old has no party affiliation, but has gained a reputation as an eloquent speaker not afraid to address controversial issues.
He will replace Christian Wulff, who resigned last month in a scandal over financial favours.
Chancellor Angela Merkel had supported Mr Wulff, her ally, against Mr Gauck when they ran against each other for the largely ceremonial role of president in 2010.
This time round she has backed Mr Gauck, although observers say her hand was forced by the liberal Free Democrats, whose support she needs in the coalition government.
By all accounts, Mrs Merkel likes him as a person, the BBC’s Stephen Evans in Berlin reports.
The question is, he says, whether Mr Gauck will be too outspoken for her political needs – say during a visit by a dignitary from an oppressive regime.
Our correspondent says the appointment means that the political leader and the head of state of a united Germany both grew up in the old East Germany – something few would once have imagined.
Mr Gauck was elected by an overwhelming majority at the Bundestag on Sunday, easily defeating his main rival – former Nazi hunter and journalist Beate Klarsfeld. She won 126 votes.
Lawmakers and dignitaries greeted the result with a standing ovation.
“What a beautiful Sunday,” Mr Gauck then said, prompting loud cheers in the chamber.
The new president and Mrs Merkel share a similar background.
They were both raised in the East, which disintegrated in 1989 with the fall of the Berlin Wall.
Mrs Merkel is the daughter of a Lutheran pastor, while Mr Gauck is both a pastor himself and the son of a pastor.
Mr Gauck became interested in politics in the East after his father was deported to Siberia for his civil rights activism.
He became a Lutheran pastor after opting to study theology when other university courses were denied him because of his father’s dissidence and because he was not a member of the communist youth organisation.
As a pastor, he held services which preceded the demonstrations that eventually toppled the communist government.
After the fall of the wall, Mr Gauck was made head of the body which investigated the activities of the Stasi, the East German secret police – earning the admiration of all but diehard communists for his work in exposing the crimes of the communist era.
In recent years he has concentrated on campaigning against both left and right extremist threats to Germany’s democratic system.
Mr Gauck describes himself as a “liberal left conservative”, and has expressed support for the policies of both Social-Democrat and Christian-Democrat coalition governments on a non-partisan basis.
A father of four, he is separated from his wife.
His partner since 2000, the journalist Daniela Schadt, will take on the ceremonial duties of First Lady.