(CNN) Germany's Ursula von der Leyen has been elected as the European Commission's first female president.

Her nomination was approved by 383 votes in a secret ballot on Tuesday evening at the European Parliament in Strasbourg, France.

There were 327 votes against her and 22 abstentions. After being elected by a narrow margin of just nine votes over the required 374, von der Leyen called for a "united and strong Europe."

The 60-year-old outgoing German defense minister and multilingual mother of seven will succeed Jean-Claude Juncker, who has served as president since 2014 and will step down on October 31.

She will be tasked with leading the EU's executive body and providing political guidance to the Commission, which proposes new laws, manages the EU budget and is responsible for enforcing EU law.

Prior to the vote, von der Leyen made a series of promises to attract the support of parliament members from across the political spectrum.

Speaking in parliament on Tuesday, she said that she wanted Europe to be the first "climate-neutral continent" in the world, proposing a new "green deal" to make the EU carbon neutral by 2050.

Von der Leyen also spoke on gender equality, and said that she would propose to add violence against women to the list of EU crimes.

In a letter on Monday addressed to the parliament's Progressive Alliance of Socialists and Democrats, von der Leyen had also said that she would propose a " new pact on migration and asylum ," that would establish a "new way of burden sharing," and would plan to bring the EU's border force Frontex to 10,000 staff by 2024.

'A huge challenge'

Von der Leyen was congratulated by leaders across the 28-country bloc.

In a message posted to Twitter, Junker congratulated von der Leyen for being the first woman to lead the commission and said: "This job is a huge responsibility and a challenge. I am sure you will make a great president. Welcome home!"

German Foreign Minister Heiko Maas said in a Twitter post: "Congratulations to @vonderleyen. She campaigned for a united and strong EU, now we want to work on this together. The world doesn't wait for Europe."

Von der Leyen will assume her position on November 1, one day after Britain's current scheduled withdrawal from the EU.

In a press conference after her election, Ursula von der Leyen spoke on Brexit, saying she will work in a "constructive way" with any new UK leader ahead of the October 31 deadline.

She declined to say if she would rather see Boris Johnson or UK Foreign Secretary Jeremy Hunt, the frontrunners for the Conservative leadership contest to become Britain's new Prime Minister.

Asked about winning the vote in a slim majority, von der Leyen said she will work with pro-European parties for "stable majorities."

"I don't know who voted for me, I know it was very difficult to achieve a majority," she said.

A controversial nomination

Some German media outlets say it's "good news" for the military that von der Leyen is leaving her position as defense minister.

Von der Leyen is a long-time ally to German Chancellor Angela Merkel, and is the only minister to have served in Merkel's cabinet since she came to power back in 2005.

In a statement, Merkel congratulated her, saying she looked forward to "good cooperation" with von der Leyen as "a new partner" in Brussels. "After over 50 years, a German will be at the top of the European executive," she noted.

Von der Leyen's nomination to replace Juncker was unexpected since von der Leyen wasn't even a candidate. Some have described her nomination as a backroom deal in Brussels.

Ahead of the vote, von der Leyen faced a lot of criticism, particularly from Merkel's coalition partners -- the Social Democrats (SPD) -- who were upset that EU leaders ignored the top candidates after days of horse-trading.

European leaders nominated von der Leyen to lead the Commission after they failed to agree on any of the nominees put forward by European political parties ahead of the EU elections. Von der Leyen beat the original frontrunner for the role, Dutch socialist Frans Timmermans.