(CNN) Europe's leaders have agreed to give two of the top four European Union jobs to women, but only after a marathon set of talks that exposed the continent's simmering divisions.

German defense minister Ursula Von Der Leyen emerged as nominee for president of the European Commission, and International Monetary Fund managing director Christine Lagarde , who is French, was put forward for the presidency of the European Central Bank.

Von Der Leyen's role must be confirmed by a vote in the European Parliament. If elected, she would be the first woman to lead the European Commission. Lagarde will be the first woman to head the bloc's central bank.

Outgoing European Council president Donald Tusk called the appointments "a perfect gender balance."

The deal was a classic European result, after days of backroom horse-trading that was bitter even by Brussels standards.

The choice of Von Der Leyen, seen as a hawkish conservative, was designed to placate Hungary's hardline leader Victor Orban. His cohort of like-minded Eastern European leaders had joined with Italy to block the original frontrunner for the role, Dutch socialist Frans Timmermans, at the last minute.

That maneuver had infuriated France and Germany. Lagarde's unexpected appointment was designed to keep French President Emmanuel Macron on side.

The compromise may yet fall apart when it comes up against a fractious European Parliament. Elections in May injected the body with a new intake of assorted populists and trouble-makers. The parliament's socialist group was said to be infuriated by the candidacy of Von Der Leyen as president of the European Commission, the bloc's executive body.

As part of the deal, Belgian Prime Minister Charles Michel was also elected president of the European Council, to replace Tusk. Spanish foreign minister Josep Borrell Fontelles will be high representative for foreign affairs and security policy.

The appointments followed a tense series of negotiations. A summit broke up on Monday, after all-night talks failed to reach an agreement.

Tusk appeared relieved that a deal had been done. "We have chosen two women and two men for the four key positions -- a perfect gender balance," he said. "I am really happy about it, after all Europe is a woman," he added, in a reference to Greek mythology.

Lagarde said she would temporarily relinquish her duties as managing director of the IMF during the nomination period.