Ursula von der Leyen has been confirmed as the European commission’s first female president and the first German in the job for more than 50 years.

In a secret ballot, MEPs voted narrowly to support the German defence minister as a replacement for Jean-Claude Juncker when he steps down on 31 October.

She won the support of 383 MEPs, nine votes more than required to secure an absolute majority but below the 400 threshold that would have given her a stable majority to get her policies through parliament over the next five years.

She will take over from Juncker on the day that Boris Johnson, who is likely to be the next British prime minister, has said he will take the UK out of the EU with or without a deal.

Von der Leyen said she would be open to Brexit being delayed further “for a good reason” although she insisted the withdrawal agreement would not be renegotiated.

After the announcement of the result, she said: “The trust you place in me is confidence you place in Europe. Confidence in a united and strong Europe, from east to west, from south to north. The confidence in a Europe that is ready to fight for the future rather than fight against each other.”

Asked whether she would prefer Johnson or Jeremy Hunt to become the next British prime minister, she told reporters: “I do not know [either] of them personally and there is a golden rule which I respect that I will work in a very constructive way with every head of state and government.”

Q&A What does the European commission president do? Show Hide The president is proposed by the European parliament and nominated by the European council of leaders of the EU member states. They lead the commission's work in implementing EU policies, chair the weekly commission meetings and set its policy agenda. They also represent the EU at European council meetings, G7 and G20 summits and at bilateral summits with third countries. The role was held by Jean-Claude Juncker from November 2014 until July 2019, when he was replaced by Ursula von der Leyen, the former German defence minister. Photograph: Jean-François Badias/AP

Von der Leyen’s emergence as EU leaders’ choice for the post two weeks ago had come as an unwelcome surprise to the Socialists and Democrats group, and even to some in the centre-right European People’s party (EPP) of which she is a member.

She had been nominated by the leaders after 50 hours of arduous negotiations despite not being one of the spitzenkandidats, or lead candidates, who campaigned before May’s European elections to head the EU’s executive branch.

Juncker’s appointment to the job in 2014, as the first spitzenkandidat, whose position relied on a the EPP’s emergence in the elections as the biggest group, had been seen as an important transfer of power away from EU capitals to the European parliament.

But opposition to Von der Leyen’s candidacy appeared to melt away after a 30-minute speech on Tuesday morning in which she made a series of left-leaning pledges to win over the socialists and stressed the importance of her being the first woman to be nominated by the heads of state and government.

“Exactly 40 years ago, the first president of the European parliament, Simone Veil, was elected and presented her vision of a united Europe,” Von der Leyen said. “It is thanks to you, and to all the other European icons, that I present to you today my vision of Europe. And 40 years later, it is with great pride that it is finally a woman who is the presidential candidate of the European commission.”

Veil, a survivor of the Holocaust who became only the fourth woman to be buried in the Panthéon in Paris after her death last year, was one of France’s most revered politicians, known for her battle as health minister to legalise contraception and abortion.

Von der Leyen committed in her speech to ensuring full gender equality among the 28 commissioners that she would lead in Brussels.

“If member states do not propose enough female commissioners, I will not hesitate to ask for new names,” she said. “Since 1958 there have been 183 commissioners. Only 35 were women. That is less than 20%.”

She went on to commit to establishing a pan-EU guarantee of free healthcare and education for every child. “I know as a mother of seven that it makes a difference for their entire life if children have access to education, sports, music, healthy food and to a loving environment”, she said.

In policies designed to win over the socialists, she pledged to establish an EU-wide minimum wage, a fund to prop up national welfare systems in the case of an economic crisis and to ensure flexibility in the tax and spend restraints on eurozone countries.

She also committed to a far-reaching environmental programme, including a “green deal”, offering billions of euros in investment and a new EU carbon border tax, with the aim of achieving carbon neutrality on the continent by 2050.

Profile Who is Ursula von der Leyen? Show Hide Ursula von der Leyen has been president of the European Commission since 1 December 2019. Born in 1958, is the daughter of Heidi and Ernst Albrecht, the latter having been a senior politician in the centre-right Christian Democratic Union who rose to be governor of the state of Lower Saxony. She spent the first 12 years of her life in Brussels, where her father was serving as a commission official. She studied economics at the universities of Göttingen and Münster before attending the London School of Economics where she used the pseudonym Rose Ladson because she was seen as a potential target for West German leftwing extremists. Von der Leyen then read for a medical degree, becoming a gynaecologist, and only entered politics at 42. A mother of seven, she has held government positions as labour and family affairs minister, driving forward key policies on gender quotas for company boards and improved maternity and paternity pay and rights. As commission president, Von der Leyen will represent the EU on the world stage, and her key tasks include building a working relationship with Donald Trump’s White House, and dealing with the next stage of post-Brexit trade negotiations with the UK.

Daniel Boffey in Brussels and Philip Oltermann in Berlin Photograph: Jean-François Badias/AP

In her biggest cross-party promise to MEPs, she said she would allow the parliament the right to propose legislation.

“Anyone who wishes to help Europe will find in me a passionate fighter by their side,” she said. “Anyone seeking to split and destroy our values will find a fierce opponent.”

Iratxe García, the Spanish leader of the Socialists and Democrats group, said: “We were very sceptical when the candidate came to our group last week, but over the past days we have to admit that she embraced our group’s core demands, with specific proposals for legislation.”

The leader of the liberal Renew Europe group, Dacian Cioloș, said he expected that fewer than five of his 108 MEPs had voted against Von der Leyen, who spoke in fluent English, French and German during the debate in parliament.

Cioloș said he had also received assurances that his fellow liberal Margrethe Vestager, a former Danish finance minister who is currently the commissioner for competition, would be appointed as an executive vice-president on an equal footing with the socialist group’s Frans Timmermans.

Representatives from the governing parties in Hungary and Poland criticised Von der Leyen’s pledge to continue with the commission’s attempt to block or reverse judicial changes in their countries.

“Lady Justice is blind – she will defend the rule of law wherever it is attacked,” Von der Leyen had told the parliament.

Green MEPs were among the 327 MEPs who voted against her candidacy. Their co-chairman Ska Keller said there had not been enough “green content” to her proposed green deal.

Von der Leyen, a close ally of Angela Merkel, becomes the first German commission president since Walter Hallstein served from 1958 to 1967.

Martin Selmayr, the commission’s German secretary general, has said he will leave his post next week. The convention is that the two top posts in the EU executive are not held by nationals of the same member state.