Germany's parliamentary assembly has elected Frank-Walter Steinmeier, a Social Democrat, as the country's president.
The position of president in Germany is largely ceremonial, because the chancellor is the official head of government and has a higher profile on the world stage.
Steinmeier previously served as vice chancellor and foreign minister under current Chancellor Angela Merkel.
He was elected by the vast majority of the assembly, receiving 931 out of 1,253 votes. His predecessor, Joachim Gauck, did not seek another term and will step down on March 18.
"This country for many in the world has become an anchor of hope," Steinmeier said after his election. "We give others courage, not because everything is good, but because we have shown that it can be better," he said.
Steinmeier, 61, has been a vocal critic of US President Donald Trump. He described Trump in August as a "hate preacher," likening him to right-wing populists in Europe who "make politics with fear," German news agency DPA reported.
Steinmeier also expressed concerns about Trump's comments that NATO, the political and military alliance between North America and Europe, is obsolete.
European Council President Donald Tusk sent his congratulations to Steinmeier.
"Your appointment comes at a critical moment for Europe. The many external and internal challenges we are facing could hardly be more severe. In times like these, European unity is more important than ever, and I look forward to Germany's continued contribution to the European project," he said.
Tusk's comments alluded to Britain's decision to pull out of the 28-nation European Union and growing anti-EU sentiment in many parts of the regional bloc.
Germany is the union's largest economy and has played a major role in the region's refugee crisis. The Merkel government has implemented an open-door policy that has welcomed more than 1 million asylum-seekers over the past two years.