Germany's parliament has elected Olaf Scholz as the country's ninth post-war chancellor, opening a new era for the European Union's most populous nation after Angela Merkel's 16-year tenure.

Mr Scholz's government takes office with high hopes of modernising Germany and combating climate change, but faces the immediate challenge of handling the country's toughest phase yet of the coronavirus pandemic.

He won the support of 395 legislators on Wednesday.

His three-party coalition holds 416 seats in the 736-seat lower house of parliament.

Mr Scholz will be formally named as chancellor by Germany's president and sworn in by the speaker of parliament later on Wednesday.

He exchanged fist bumps with legislators from across the political spectrum after the announcement. Mrs Merkel, who is no longer a member of parliament, looked on from the spectators' gallery as parliament voted. Members gave her a standing ovation as the session started.

Mr Scholz, 63, Germany's vice chancellor and finance minister since 2018, brings a wealth of experience and discipline to an untried coalition of his centre-left Social Democrats, the environmentalist Greens and the pro-business Free Democrats.

The three parties are portraying their uniting of former rivals as a progressive alliance that will bring new energy to the country after Mrs Merkel's near-record time in office.

"We are venturing a new departure, one that takes up the major challenges of this decade and well beyond that," Mr Scholz said Tuesday.

If the parties succeed, he added, "that is a mandate to be re-elected together at the next election".

The new government aims to step up efforts against climate change by expanding the use of renewable energy and bringing Germany's exit from coal-fired power forward from 2038, "ideally" to 2030.

It also wants to do more to modernise the country, including improving its notoriously poor mobile phone and internet networks.

It also plans more liberal social policies, including legalizing the sale of cannabis for recreational purposes and easing the path to German citizenship while pledging greater efforts to deport immigrants who do not gain asylum.

The coalition partners want to lower the voting age in national elections from 18 to 16.

There will be an increase in the minimum wage to 12 euros (£10) per hour from the current 9.60 euro, which Mr Scholz has said "means a wage increase for 10 million".

The coalition also aims to get 400,000 new apartments per year built in an effort to curb rising rental prices.

Mr Scholz has signalled continuity in foreign policy, saying the government will stand up for a strong European Union and nurture the trans-Atlantic alliance.

The alliance brings both opportunities and risks for all the participants, perhaps most of all the Greens.

After 16 years in opposition, they will have to prove that they can achieve their overarching aim of cutting greenhouse gas emissions in a three-way alliance with partners who may have other priorities.

Green co-leader Robert Habeck will be Mr Scholz's vice chancellor, heading a revamped economy and climate ministry.

The agreement to form a coalition government between three parties that had significant differences before the election was reached relatively quickly and in unexpected harmony.

"If the good cooperation that worked while we were forming the government continues to work, it will be a very, very good time for the tasks that lie ahead of us," Mr Scholz said.

He acknowledged that dealing with the pandemic "will demand all our strength and energy".

German federal and state leaders last week announced tough new restrictions that largely target unvaccinated people. In a longer-term move, parliament will consider a general vaccine mandate.

Germany has seen daily Covid-19 infections rise to record levels this fall, though they may now be stabilising, and hospitals are feeling the strain. The country has seen over 103,000 Covid-19 deaths in the pandemic so far.

Mrs Merkel has said she will not seek another political role after shepherding Germany through a turbulent era.

The 67-year-old has not disclosed any future plans but said earlier this year that she will take time to read and sleep, "and then let's see where I show up".