Gaining the support of both groups, on top of endorsement by her fellow conservatives, is expected to give her legitimacy, allowing her to tackle controversial issues such as climate change, trade and maintaining democracy in the bloc.
Rejection by the European legislature would have been a painful blow for the bloc, beset by challenges ranging from trade to Brexit and erosion of democratic norms, and a headache for EU leaders who would have to come up with another candidate in a month.
As head of the EU executive, von der Leyen will be in charge of trade negotiations, economic and climate policy for 500 million Europeans and antitrust rulings involving powerful tech giants.
She secured 383 votes to 327 against, the speaker of the assembly, David Sassoli, said. The threshold was 374.
"The trust you placed in me is confidence you placed in Europe. Your confidence in a united and strong Europe, from east to west, from south to north," the German conservative said. "It's a big responsibility and my work starts now."
"Let us work together constructively because the endeavor is a united and strong Europe," said von der Leyen, who will take up her new role on November 1.
The liberal group Renew Europe and the Socialists and Democrats Group had earlier announced support for the 60-year-old, who this week resigned as German defense minister, regardless of the EU lawmakers' decision.
Earlier on Tuesday, von der Leyen set out her climate goals, going further than current targets, in a bid to convince both socialists and liberals. She had already pledged the ambitious targets in letters to the two groups the previous day.
"Our most pressing challenge is keeping our planet healthy. This is the greatest responsibility and opportunity of our times. I want Europe to become the first climate-neutral continent in the world by 2050," she told EU lawmakers.
She added she would propose a Green Deal for Europe in her first 100 days in office, turn parts of the European Investment Bank into a Climate Bank and introduce a Carbon Border Tax.
Von der Leyen promised to defend the rule of law, took aim at U.S. tech giants' low tax bill in Europe and said she would update EU-wide norms for tackling the migrant issue.
"We need to address the legitimate concerns of many and look at how we can overcome our differences," she said.
In her biggest cross-party promise, von der Leyen offered to help allow the chamber the right to propose new legislation - currently the Commission's prerogative.