(CNN)Angela Merkel was sworn in as Chancellor of Germany after lawmakers voted to re-elect her as leader in a close vote on Wednesday morning.
She will now begin a historic fourth term as Chancellor.
The vote in parliament ended almost six months of political turmoil after a federal election saw millions of voters desert the two mainstream parties -- Merkel's Christian Democratic Union and the Social Democratic Party (SPD) -- turning instead to parties on the left and right.
At 171 days, it is by far the longest period in modern German history between a federal election and the election of a Chancellor.
In a secret ballot, 364 of the Bundestag's 709 members voted in favor of Merkel -- nine more than the 50% required. Thirty-five MPs from the parties governing under Merkel did not vote to re-elect her.
Speaking on Monday in expectation of her re-election, Merkel said: "I think everyone has the feeling it's time to finally start working. A new departure for Europe, a new dynamic for Germany, new cohesion for our country -- that's what we have before us... So there is a lot of work ahead."
Merkel's victory marks the final stepping stone on the path to Germany's new government -- a renewal of the so-called grand coalition ("GroKo") between the Chancellor's CDU/Christian Social Union alliance and the SPD.
The former leader of the SPD, Martin Schulz, had initially ruled out a new GroKo, pledging to take his party into opposition, but was forced to change his stance after coalition talks between the CDU, Green Party and liberal Free Democratic Party collapsed in November, raising the possibility of new elections.
After weeks of negotiations, a coalition treaty was produced and later approved by SPD members who voted via postal ballot. But many SPD members and politicians remain unhappy with their party's involvement in the new coalition.
Government must 'win back lost trust'
In a speech nominating Merkel as Chancellor on Wednesday morning, President Frank-Walter Steinmeier warned that the new coalition must win back the trust of voters and protect Germany's liberal democracy, alluding to the rise of the far-right Alternative for Germany (AfD) without mentioning the party by name.
"In order to win back lost trust, a simple restoration of old ways will not suffice. This government has to prove itself in new and different ways."
"The liberal democracies of the West are beset with challenges -- from without as well as from within," he said. "Even in parts of Europe elections are being won with isolationism, nationalism and an unwillingness to compromise."
He urged Germany to set an example to the world by remaining democratic, outward-looking and peaceful, adding that the country is in a better position than many others to prove the value of liberal democracy.
"We have proven in the past that we can free ourselves from the most difficult situations with courage and determination," he said.
The renewal of the grand coalition means the AfD is now officially the lead opposition party in parliament.
Founded in 2013, the party ran on a virulently anti-immigration platform that proved popular with voters in the September election.
The party surged into third place in the election with 12.6% of the vote, the first time in decades that a far-right, openly nationalist party had won seats in Germany's federal parliament.
AfD politicians have campaigned strongly against Merkel and her policies. Following the election result in September, co-leader Alexander Gauland promised his party would provide staunch opposition to the new government, adding: "We will hunt them. We will hunt Mrs. Merkel or whomever. And we will take back our country and our people."