Frank-Walter Steinmeier, Germany's former foreign minister, has been elected as the country's new president, the 12th person to hold the largely ceremonial post in the post-war era.
Steinmeier on Sunday won 931 out of 1,260 valid votes cast by the members of the Federal Assembly, which is made up of 630 federal members of parliament and an equal number of delegates from 16 states.
"Let's be brave, because then we don't have to be afraid of the future," Steinmeier said in his acceptance speech.
He said the world faces "rough times", but that Germany, as a functioning democracy, had the responsibility to fight for stability.
German Chancellor Angela Merkel congratulated Steinmeier and said she was convinced he would be an excellent president who would have the support of the vast majority of the people.
"This is a good day for Germany," Merkel said.
A seasoned Social Democrat politician who had served as foreign minister until last month, Steinmeier had the support of Chancellor Angela Merkel's "grand coalition" of centre-right and centre-left parties.
"I would like, as federal president, to be something of a counterweight to the current tendency towards boundless simplification," Steinmeier, 61, said before the election.
While on a tour of Germany to promote his candidacy, Steinmeier emphasised mutual respect, strengthening democracy, taking a broader view, tolerance and solidarity as the ideas that will inform his presidency.
His predecessor, Joachim Gauck, steps down on March 18.
The German president has little executive power, but is considered an important moral authority and symbol of the country as its host for visiting dignitaries.