Europe is this week coming to terms with the divisions and drama around the nomination of Ursula von der Leyen as the new European Commission president. Was this a grubby backroom deal, or a case of EU leaders simply reclaiming control over Europe's most coveted post?

The bruising process saw Ms von der Leyen win the last-minute support of EU leaders on Tuesday, but the medics are picking their way through the battlefield to see who is most seriously injured.

A narrative has developed that the Spitzenkandidat process itself has been irreparably damaged, that Chancellor Merkel is a weakened figure, and that the outcome reflects badly on European democracy.

All three notions can be contested.

Firstly, a reminder of the Spitzenkandidat process. The idea was championed by the European Parliament in 2013 as a way to help voters feel they had a stake in electing the European Commission president.

The main political groups would nominate their "lead candidate" long before the European Parliament elections, who would put forward their ideas so voters could chose and, if they wished, vote for the national party which was a member of the European group whose lead candidate was known.

In 2014 it delivered Jean-Claude Juncker, the lead candidate of the centre-right European People’s Party (EPP).

Ursula von der Leyen and Jean-Claude Juncker

However, it was not an entirely pure process back then. Angela Merkel, and indeed most other leaders, felt this was a power grab by the parliament and contrary to the EU treaties, which spell out that EU leaders get to nominate a candidate, "taking account of" the results of the European Parliament election.

Mr Juncker was gifted the position when the Socialists and Democrats (S&D) group gave their consent thanks to a deal that would see Martin Schulz remain the socialist president of the European Parliament for a five-year term, instead of a two-and–a-half-year term.

In 2018 Manfred Weber, a German MEP, was overwhelmingly elected the EPP's Spitzenkandidat at a party congress in Helsinki.

However, Chancellor Merkel’s public support for Mr Weber was nuanced to say the least. EPP sources suggest that a year previously the Chancellery had their hopes pinned on Peter Altmaier, the Federal Minister for Economic Affairs and Energy and a member of Ms Merkel’s CDU party, as Commission President.

Ms Von der Leyen’s name was also mentioned, but only in dispatches. But both politicians had ministerial experience. Mr Weber had not.

However, as the European Elections approached, the EPP was sticking by Manfred Weber. Toiseach Leo Varadkar supported him in Helsinki, and publicly supported him when asked in the run up to May’s elections.

Other EU leaders continued to question the Spitzenkandidat idea. Xavier Bettel, the Luxembourg prime minister, told reporters in Romania in May: "Spitzenkandidat is a party organisation. Journalists and we speak about Spitzenkandidaten. Ask my voters - they have no clue who is the Spitzenkandidat from any party."

Emmanuel Macron was the most explicitly opposed. The French President had never supported the idea, preferring transnational lists as a way to give voters more ownership of appointments of the top jobs. "I don't think this is the right way," he said in early May. "Our citizens have had enough of pre-cooked meals."

But Macron had been pointedly dismissive of Manfred Weber, repeatedly talking about the need for "competent" candidates who would shine on the world stage.

When voters went to the polls in late May, the increase in turnout to 51% was a tonic for the European project, but the actual result muddied the Spitzenkandidat waters. The EPP lost 34 seats and the Socialists, who had put forwards the Dutch EU Commissioner Frans Timmermans as lead candidate, lost 31 seats.

The Greens surged by 22 seats to 74, while the Liberal group won an extra 39 seats to hold 108 in the new parliament, mostly thanks to Emmanuel Macron’s scores.

A fragmented parliament meant neither the EPP nor the Socialists had won a commanding majority, even though the EPP secured the most seats at 182.

This meant that a repeat of 2014 was out of the question. 

As such, in the aftermath of the results the European Council decided to appoint formateurs - prime ministers from the 27 EU leaders - who would, depending on their political affiliation, liaise with the European Parliament’s relevant political groups to chart a way forward.

By the time of the June EU summit there was little progress. The EPP were insisting on Mr Weber, and the Socialists were declaring that a rainbow coalition of Liberals, Greens, independents and the far left could rally behind Frans Timmermans.

Donald Tusk, the European Council president duly called leaders back to Brussels for another attempt last Sunday, 30 June.

Three days later the European Parliament was due to hold its first plenary, where it would elect a president. Leaders were anxious that they reach agreement before the parliament started the ball rolling.

At the start of the week things seemed deadlocked. However, a meeting took place in Berlin on Wednesday, 26 June, that would change everything.

The meeting was attended by Chancellor Merkel, Manfred Weber, Ms Merkel’s CDU successor Anegret Kramp-Karrenbauer, EPP president Joseph Daul, and Markus Soeder, leader of the CSU, the sister party of the CDU.

It’s unclear which of the participants came up with the idea, but a plan was hatched whereby the socialist candidate Frans Timmermans would be supported as Commission President, and Mr Weber would be nominated president of the European Parliament for a five-year term.

German Chancellor Angela Merkel speaking to the press in Brussels

Two days later Ms Merkel flew to the G20 in Osaka. The compromise plan was put to Mr Macron, the Dutch prime minister Mark Rutte, from the Liberals, and the Spanish prime minister Pedro Sanchez.

They agreed to support it and to ensure that the EPP, the Socialists and the Liberals would face down the opposition to the Dutchman from the leaders of Poland, Hungary, Slovakia and Czechia (the so-called Visegrad countries), who resented his investigation of alleged rule of law violations in Poland and Hungary.

As Sunday’s summit approached, Mr Timmermans’ star was rising through various news reports. However, when leaders arrived in Brussels the Osaka compromise, as it became known, ran into immediate opposition, first from the Visegrad group but also from the EPP itself.

The summit was due to start at 6pm. At lunchtime senior EPP figures held a turbulent meeting, involving a number of centre-right prime ministers, Joseph Daul and Manfred Weber. There was disbelief that Merkel would cook up a deal that would hand Europe’s top job to a Socialist. 

The Croatian prime minister Andrej Plenkovic and the Latvian prime minister Krišjanis Karinš, who had been the European Council interlocutors for the EPP group in the parliament, had been kept entirely out of the loop.

The meeting ran over by 40 minutes.

Afterwards both men were dispatched to tell the other leaders that the EPP was sticking by Manfred Weber.

An hour later the EPP held its traditional pre-summit gathering. Angela Merkel, who had not attended the earlier EPP meeting, spoke first. She was furious at reports of what had materialised at lunchtime. She said Europe was about compromise, and that giving Mr Weber the position of president of the parliament for five years was a noble consolation prize.

According to a number of sources, Ms Merkel’s argument was rejected by almost everyone in the room, except for Markus Soeder.

The Chancellor was told that 79% of all EPP delegates had voted for Mr Weber in Helsinki. As such the EPP had no mandate but to push for "one candidate, one job", that is Manfred Weber getting the European Commission president position.

With the Socialists and Liberals having presumed the Osaka deal would hold, the sudden hardline from the EPP meant the summit was deadlocked. Donald Tusk, who had also been bypassed in Osaka, kept up bilateral meetings throughout the night to no avail.

EU leaders resumed on Monday morning after a short break, but everyone was exhausted. Rutte, Merkel and Sanchez were all suffering jet-lag from the dash to Osaka.  

"They were shattered on Monday," says one source. "They were physically exhausted. Monday was just a recovery period."

By noon Donald Tusk decided to call it a day. The summit would go into a third day on Tuesday. Joseph Daul and Manfred Weber travelled to Strasbourg. Angela Merkel returned to Berlin.

However, on Monday night phone contacts resumed after some leaders had got some sleep. The name of Michel Barnier, the EU’s chief negotiator, had re-emerged.

Mr Tusk had done a straw poll of leaders in the run up to the summit, and a majority had felt that Mr Barnier was the "least unacceptable" candidate (Margarethe Vestager, the Danish Competition Commissioner was second on that list). The word was that Emmanuel Macron would back Mr Barnier, even though he was from a different political group.

Kristelina Georgieva, the former Bulgarian prime minister and currently the head of the World Bank, was also circulated as a possible candidate, but that was knocked down by none other than the current Bulgarian premier Boyko Borisov.

However, for the first time Ursula von der Leyen’s name was mentioned in phone calls. Within this flurry of contacts it was soon clear that Mr Weber did not stand a chance. But if he was out, then so was Frans Timmermans, according to the brutal logic of politics.

"We always felt that if they killed our candidate," says a senior EPP source, "we’d kill the Liberal and Socialist candidates."

On Tuesday morning the EPP held another meeting involving senior officials, centre-right prime ministers and Manfred Weber. Jean-Claude Juncker, the outgoing Commission President and a grandee of the EPP, took a more active role in the debate, warning the meeting that if they didn’t choose a candidate that day, then the parliament would start the ball rolling.

There was then a change in the negotiating team.

Jean Claude Juncker and Donald Tusk joined Karinš, Plenkovic and Ms Merkel. By then the news for Manfred Weber had got worse. Not only would he not become Commission president: he would not be considered as Germany’s next Commissioner either.

The EPP meeting spilled over into the European Council meeting itself, meaning the summit, which was meant to resume at 11am, did not start until 3.30pm.

But a path was opening up for Ursula von der Leyen. The fact that she was a female candidate chimed with Donald Tusk’s insistence that there would be a genuine gender split in the top four jobs.

It also potentially soothed lingering resentment at the growing number of senior German officials within the EU institutions in recent years. Having a German Commission president would also mean the departure of the German (and allegedly ruthless) official Martin Selmayr who was appointed Commission secretary general in questionable circumstances.

By the end of Tuesday a package had taken shape, with von der Leyen as Commission President, Christine Lagarde as head of the ECB, Josep Borrell, the Spanish socialist as High Representative for Foreign Policy and Charles Michel, the Belgian caretaker prime minister, as President of the European Council.

When the dust settled, it looked like Emmanuel Macron had triumphed. He had "killed" Weber, got a French woman in as head of the ECB and a francophone fellow Liberal as Council president. Ursula von der Leyen is also a fluent French speaker.

Angela Merkel may have lost Manfred Weber as a candidate, but she now had the first German Commission President in over 50 years, and someone who is a close friend.

The Spitzenkandidat process received a setback in that the man who put himself forward to voters as the centre-right candidate was buried by events; but the party which won the most seats in the elections still got the top job.

Ms Von der Leyen is expected to launch a charm offensive to clear the 375 votes needed on 17 July at the Strasbourg Plenary to be formally approved by the European Parliament. She is expected to co-opt centre-left and green policies into her five-year Strategic Agenda in order to win over resentful MEPs, who are still furious at the nature of her nomination.

In terms of how any of this will affect the Brexit process, there are few indications of any major departure from orthodoxy.

Ms Von der Leyen is on record as saying that the EU should exercise patience with the UK given the "unknowable consequences" of a hard Brexit, but she has also remarked upon the "burst bubble of hollow promises by populists".

Charles Michel has been noted for taking a hawkish stance against the UK when it comes to granting extensions to Article 50.

Any notion, however, that the filling of the top jobs marks a clean slate in the EU’s posture on Brexit is fanciful. 

At a state dinner in Berlin in honour of President Michael D. Higgins on Wednesday night, Germany’s President Frank-Walter Steinmeier formally knocked down any notion that the UK could renegotiate the Withdrawal Agreement or that Ireland’s interpretation of the risks to the peace process would be pushed aside at the last minute.

"On no account must the United Kingdom’s departure from the European Union be allowed to reopen these old wounds [in Ireland]," he told assembled guests in the Schloss Bellevue residence.

"Your country has our full solidarity. We have reiterated this pledge in recent months: Germany stands firmly by Ireland’s side.

"The European Union’s value and internal cohesion have rarely been so plain as during the withdrawal negotiations. Ireland is part of this Union. And Ireland’s core interests are and will remain the EU’s core interests."

The stage is now set for the final weeks of the Conservative Party leadership campaign. The view in Europe can be summed up in the final remarks of President Steinmeier: "All EU member states have clearly stated that renegotiation is not an option. We just have to hope that the new government in London realises that too."