There were 383 votes in favour of the move. The center-right defence minister needed 374 votes to be approved.
Ms von der Leyen, a Christian Democrat in the European People's Party, is the first woman to hold the job and will replace Commission President Jean-Claude Juncker on November 1.
She was a last-minute candidate and many legislators were angry none of their lead candidates were selected for the top job.
The announcement comes after Brexit Party MEPs booed Ms von der Leyen after she said the UK’s exit from the bloc could be delayed again beyond October 31.
She clashed with the party's leader Nigel Farage in the European Parliament as she insisted she would allow another Brexit extension if there were good reasons.
The German politician told MEPs in Strasbourg she respected but regretted the UK's decision to leave the EU.
She said: "We cannot talk about Europe without talking about our friends from the UK.
"For the very first time, in 2016 a member state decided to leave the EU. This is a serious decision, we regret it but we respect it.
"Since then, together with the current government of the UK, the EU has worked hard to organise the orderly departure of the UK."