German Defense Minister Ursula von der Leyen was confirmed Tuesday for the European Union’s most powerful job, in a nail-biter of a vote that put Europe’s divisions on stark display.

Von der Leyen, a political survivor who is a longtime ally of Germany’s center-right chancellor, Angela Merkel, will become the first woman to hold the five-year presidency of the European Commission. She will take on a trade war with the United States, the management of a treacherous relationship with China, the departure of Britain from the European Union and a clutch of marauding euroskeptic leaders who want to break the bloc from within and without.

She passed her first test Tuesday. She needed at least 374 out of 733 votes; she got 383. The whisper-thin victory — which she greeted with clear relief — paradoxically was built with the support of Poland’s euroskeptic Law and Justice party, which announced at the last moment that it would back her.

Most euroskeptics voted against her. So, too, did many Greens and center-left lawmakers who complained that European leaders had overridden the will of European voters by installing a candidate who had not been floated during elections for European Parliament in May.

The outcome highlighted the loss of a majority for the traditional center-left and center-right parties within the legislature. Now they are forced to jostle for influence with a host of new parties, all of whom have fresh approaches toward managing Europe’s sprawling affairs.

“We are going to have to rise up for this Europe of ours,” von der Leyen said ahead of the vote. She began in French, then switched to German and English in a passionate pro-European Union speech delivered in the glassy round chamber of the Parliament in Strasbourg, France. 

She listed off the rivals to the European Union, a proudly multilateral bloc in a world riven by nationalists and authoritarian leaders. She appeared to reject, in the same breath, the influence-buying approach of China and the protectionist bent of President Trump.

“Some are turning toward authoritarian regimes. Some are buying their global influence and creating dependencies by investing in ports and roads, and others are turning toward protectionism. None of these options are for us,” von der Leyen said. “We want multilateralism. We want fair trade. We defend the rules-based order because we know it is better for us. We have to do it the European way.”

Euroskeptic lawmakers within the Parliament took turns blasting her as a creature of Brussels — she lived her first 13 years in the E.U. capital, as the daughter of an official in an early form of the bloc — and warning that European citizens would never stand for her.

A member of the far-right Alternative for Germany party said his group would not support her — but added that no one in Germany would be sad if she won the vote and left national politics.

“No one will rue your departure,” Jörg Meuthen said. 

E.U. leaders nominated her for the job this month, after they struggled to find someone who could satisfy everyone from the leftist leaders of Greece to the smoldering anti-migration leader of Hungary.

Within the Parliament, von der Leyen was not assured of support even among pro-European forces. Angry center-left lawmakers and Greens complained that the E.U. leaders’ decision to ignore contenders put forward by political parties would undermine the new leader’s legitimacy.

Others complained that Polish and Hungarian leaders derailed a different candidate who had been one of their top tormentors on rule-of-law issues in recent years.

Von der Leyen promised a grab bag of initiatives if confirmed. A “green deal” for Europe would try to build a continentwide effort to fight climate change and boost the economy. She said she wanted a bolstered border agency to protect Europe’s frontiers. And she said wanted an equal balance of women and men among the senior E.U. officials who will form the body akin to her cabinet.

Critics of the decision warned that European citizens would feel more estranged from the powerful European Commission, the body that proposes European regulations and does trade deals but whose inner workings often remain largely opaque.

“This should highlight that the average European citizen has no visibility whatsoever of the political program and the consequences stemming from his choice,” said Alberto Alemanno, a professor of European law at the HEC business school in Paris.

In the past two election cycles, the European Parliament has tried to bolster voter involvement in the pick of the top E.U. job by proposing that the candidate of the top vote-getting party in European elections be swept into office. That approach worked in 2014, when the center-right Luxembourg Prime Minister Jean-Claude Juncker took the post. But this year, the candidate of the top vote-getting party, center-right German politician Manfred Weber, faced considerable opposition — especially from French President Emmanuel Macron — for having been too soft on Hungarian Prime Minister Viktor Orban’s assault on the rule of law.

The barbs from both sides of the aisle served as a warning sign about challenges ahead.

“European elections delivered a much more fragmented Parliament,” said Agata Gostynska-Jakubowska, an expert on European politics at the Center for European Reform, a think tank. “What is going to be pretty prominent is that the euroskeptics who failed to obtain a blocking minority in the European Parliament will try to expose the vulnerabilities of this pro-European coalition.”

James McAuley in Paris contributed to this report.