* Tortuous talks on top EU posts end on third day
* ECB, European Commission to get women leaders for the first time
* Five jobs at stake in world's biggest economic bloc
* Negotiations expose deepening political divisions (Updates with quotes, details)
BRUSSELS, July 2 (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 but was immediately rejected by the socialist bloc.
"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 sends a positive message and repairs damage wrought by such a fractious summit, diplomats said.
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 myth 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.
But it was not all girl power at a torturous summit that had leaders nodding off and their police escorts slumped on chairs as groups of leaders huddled in search of a deal.
With a weakened Merkel facing a rebellion by her centre-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.
It was a clear reminder of the threats 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 nomination of Belgium's liberal caretaker prime minister, Charles Michel, to replace Tusk as chair of EU summits. In that role, Michel will be tasked with 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.
EAST EUROPEAN 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.
Possible names include Bulgarian socialist Sergei Stanishev and Manfred Weber, the German EU lawmaker who led the May election campaign for the EPP.
"It's still possible, maybe very likely, that the parliament will vote for a president from eastern and central Europe. I hope so," said Tusk, a former Polish prime minister. (Reporting by Andreas Rinke, Peter Maushagen, Alexandra Regida, Jean-Baptiste Vey, Richard Lough, Gabriela Baczynska, Alissa de Carbonnel, Belen Carreno in Brussels, Jan Lopatka in Prague, Alan Charlish and Agnieszka Barteczko in Warsaw, Francesco Guarascio in Strasbourg; Editing by Kevin Liffey and Gareth Jones)