BRUSSELS/STRASBOURG (Reuters) - European Union leaders agreed on Tuesday to name France’s Christine Lagarde as the new head of the European Central Bank and sealed a deal on filling the EU’s other top four jobs after marathon talks that have exposed deep divisions in the bloc.

Three days of summit negotiations that at times looked close to collapse ended with a deal that now must be approved by the European Parliament and was immediately rejected by the socialist and green bloc in the assembly in Strasbourg.

“Done!” said Luxembourg’s Prime Minister Xavier Bettel, who was first to break the news on Twitter that leaders had finally clinched a deal.

Leaders hope the decision to nominate two women, Lagarde and German Defence Minister Ursula von der Leyen, to the top of EU decision-making for the first time will send a positive message and repair damage wrought by such a fractious summit, diplomats said.

The discord echoed a wider fracturing of the EU’s political center that was evident in May’s European Parliament elections that delivered a more fragmented assembly in which no bloc won a majority and far-right and far-left groups performed strongly.

Under the deal, von der Leyen, a close ally of German Chancellor Angela Merkel, will replace Jean-Claude Juncker as president of the European Commission, the EU’s executive arm.

“After all, Europe is a woman,” Donald Tusk, the outgoing chair of EU summits, told reporters, referring to the ancient Greek mythical figure of Europa who gave her name to the continent.

Lagarde, once France’s first woman finance minister and since 2011 head of the International Monetary Fund (IMF), is a strong advocate of female empowerment, although she has no direct, active monetary policy experience.

The biggest task for Lagarde, who had previously denied any interest in an EU job, will be to revive the euro zone economy.

“Christine Lagarde will ... be a perfect president of the European Central Bank,” Tusk said. “I am absolutely sure that she will be a very independent president ...”

Von der Leyen, if approved, would run the powerful Commission, which supervises EU states’ budgets, acts as the bloc’s competition watchdog and conducts trade negotiations with outside countries. Her presidency would shape policy for the world’s biggest trade bloc and its 500 million people.

She once had a reputation as a flawless politician, but Brussels-born Von der Leyen has had a scandal-prone run as German defence minister, mainly over right-wing extremism in the armed forces, gaps in military readiness, and the awarding of arms contracts.

Slideshow ( 8 images )

DIVISIONS

The deal followed a tortuous summit that had leaders nodding off and their police escorts slumped on chairs as groups of leaders huddled in search of an accord.

With a weakened Merkel facing a rebellion by her center-right European People’s Party (EPP) early on in the summit, efforts to push through a deal pre-agreed with French President Emmanuel Macron met stiff resistance from Italy, Poland and others.

They scuppered a plan to install former Dutch foreign minister Frans Timmermans as Commission president.

Slideshow ( 8 images )

It was a clear reminder of the risks the EU faces from populists who officials accuse of trying to weaken the bloc’s democratic foundations as it struggles with Brexit and challenges posed by Russia, China, Iran and Donald Trump’s United States.

Timmermans, who led the Socialists’ European Parliament election campaign in May and whose name Macron and Merkel had agreed on at a G20 summit in Japan last week, was the biggest casualty of some 30 hours of negotiations.

In other decisions on Tuesday, Spain’s acting foreign minister, Josep Borrell, a socialist, was nominated as the EU’s new top diplomat in Brussels.

Macron and Spanish Prime Minister Pedro Sanchez, who had pushed hard for Timmermans, also secured the election of Belgium’s liberal caretaker prime minister, Charles Michel, to replace Tusk as chair of EU summits. In that role as European Council president, Michel will be have the job of building compromises between the 28 member states.

Timmermans and Margrethe Vestager, the lead candidate for the liberals in May’s parliament election, were put forward as deputies under von der Leyen in the next Commission, which takes office on November 1.

ITALIAN LIKELY TO LEAD PARLIAMENT

Von der Leyen, Timmermans and Vestager will all help lead the EU’s policies over the next five years on everything from climate to migration to trade.

The fifth prominent EU role up for grabs is the president of the European Parliament. Lawmakers are due to choose that person in Strasbourg on Wednesday.

The socialists chose as their candidate Italian lawmaker David Sassoli, making him the strongest contender for the presidency of the parliament, as he also has the support of the center-right grouping, the largest in the chamber, and the liberals.

But the ballot will be secret and some groups’ members could vote along national lines. A Bulgarian candidate for parliament president, Sergei Stanishev, was supported by EU leaders but eventually was rejected by most conservative and socialist lawmakers, against the will of deputies from eastern European countries.

A smooth election of the EU parliament president is seen as useful to paving the way for the endorsement by the chamber of the new commission’s president in a vote expected in the second half of July.