She was voted in by a thin majority of 383 of 733 votes cast, a historically slim margin that underscores the lingering divisions in the bloc. The outgoing European Commission president, Jean-Claude Juncker, who also faced resistance to his 2014 nomination, was elected by 422 votes out of the 729 cast.

In her acceptance speech, Ms. von der Leyen said that building coalitions would be a key part of what she does as commission president. But ultimately, she said, “in a democracy, a majority is a majority.”

European politics aside, Ms. von der Leyen has also faced scrutiny based on her track record as defense minister.

In late 2018, she was forced to admit there were “mistakes” in the awarding of consulting contracts worth millions of euros to companies suspected of being too close to the ministry. A parliamentary committee is looking into how the contracts were awarded and whether the internal investigation started by Ms. von der Leyen was in line with requirements for transparency.

Her approval by the European Parliament also opens the way for other picks for the top jobs in the European Union, most notably that of the woman chosen to lead the European Central Bank, Christine Lagarde of France. As the selection of nominees for the bloc’s leading positions is a grand bargain, a failure to confirm Ms. von der Leyen would have had a domino effect, throwing other positions, including that of the president of the European Council and the chief of foreign policy, up in the air.

Janis Emmanouilidis, an expert with the European Policy Center in Brussels, said that the turbulent process that led to Ms. von der Leyen’s confirmation reflected “the realities of the union.”

“It reflects a compromise of political parties, member states, a complex apparatus that at the end of the day comes up with a decision. It’s sometimes difficult to follow how it works, but it does work,” he said.