EU Commission president Ursula von der Leyen | Frederick Florin/AFP via Getty Images Ursula von der Leyen elected European Commission president Center-right nominee becomes first woman to lead EU.

STRASBOURG — The European Parliament on Tuesday elected Ursula von der Leyen as the next president of the European Commission — the first woman to hold the EU's top executive job.

Von der Leyen, from the center-right European People's Party, served most recently as German defense minister and is a close ally of Chancellor Angela Merkel. She will be the first German to lead the EU in more than a half-century, since Walter Hallstein served from 1958 to 1967.

Von der Leyen won 383 votes in a secret ballot, just slightly above the absolute majority of 374 she required to be elected — and far short of the 422 votes cast in favor of current Commission President Jean-Claude Juncker in 2014. There were 327 votes in opposition, 22 abstentions and one vote declared invalid.

Some EU officials said failing to cross the politically significant threshold of 400 votes signaled that von der Leyen would face an extremely difficult task governing in partnership with a Parliament that is more diverse and divided than at any other point in the EU's modern history.

As Parliament President David Sassoli announced the tally, von der Leyen briefly placed her hand over her heart and exhaled through pursed lips in a demonstrative display of relief. She smiled, raised an eyebrow and put her hand back on her chest and held it there, as applause erupted in the hemicycle. She then applauded briefly herself.

"These were definitely the most intense two weeks of my political life" — Ursula von der Leyen, president of the European Commission

"I feel so honored and I am overwhelmed and I thank you for the trust you placed in me," von der Leyen told the MEPs moments later. "The trust you placed in me is confidence you placed in Europe. Your confidence in a united and a strong Europe from east to west, from south to north. Your confidence in a Europe that is ready to fight for the future rather than fighting against each other. Your confidence in a Europe that will take the big challenges of our times together."

"My work starts now," she added.

Von der Leyen had the declared backing of the three mainstream, pro-EU groups — the center-right European People's Party, the Progressive Alliance of Socialists & Democrats (S&D), and the centrist-liberal Renew Europe group.

However, the S&D group was sharply divided over whether to back von der Leyen, with the French, German, Austrian, Belgian, Dutch, and Greek delegations all saying in an internal group meeting that they would vote against her, according to a party official. The Spanish and Portuguese delegations, pressed by Prime Ministers Pedro Sánchez and António Costa, said they would vote in favor.

The tight margin of von der Leyen's victory suggested that she may have needed the help of some other parties, including Italy's populist 5Star Movement, which is not affiliated with any group in the Parliament.

Von der Leyen will also be trailed to Brussels by an investigation, still underway in the German parliament.

In a sign of how thin and fragile her mandate appeared, she also immediately faced questions about the possibility that her majority, which included the support of some British MEPs, would effectively evaporate in the event that the U.K. completes its departure from the EU.

The Greens group, as well as right-wing and left-wing parties, had previously announced their intention to vote against von der Leyen, and the result suggested they had generally followed through on that pledge.

Aside from the divided European Parliament and her narrow margin of victory, von der Leyen will also be trailed to Brussels by an investigation, still underway in the German parliament, over allegations of mismanagement and misspending at the defense ministry during her tenure.

At a news conference with Sassoli after leaving the hemicycle, von der Leyen thanked her transition team and said she planned to spend her summer in Brussels preparing for her new job.

"You see me still overwhelmed," she said told reporters. "These were definitely the most intense two weeks of my political life."

She also reiterated some of her policy goals, including in combating climate change.

"I want to move Europe forward in the next five years to a climate-friendly Europe, a climate-friendly Continent, a Europe that serves people," she said.

Sassoli, for his part, said: "There's a lot of hope here. We have come out of our elections with the strength of citizens who want more Europe."

Follow POLITICO's live blog for the latest news, reaction and analysis after von der Leyen's election.