Theresa May was left waiting while European leaders decided the future of Brexit behind closed doors.

The prime minister had hoped to be handed an extension of the Article 50 period until 30 June before making a statement from Brussels in the early evening.

Instead, the 27 presidents and prime ministers were locked in talks long into the night after they tore up draft proposals and produced a complicated conditional plan.

Diplomats in the room painted a disorientating picture of discussions, with proposals for shorter and longer deadlines made by different countries.

EU leaders ultimately agreed that the UK could have an unconditional extension until 12 April, and a further extension until 22 May if MPs approved the withdrawal agreement next week.

"Leave means leave" - Brexit Betrayal march Show all 15 1 /15 "Leave means leave" - Brexit Betrayal march "Leave means leave" - Brexit Betrayal march Nigel Farage waves from the top deck of the Brexit Betrayal bus on the march from Sunderland to London Reuters "Leave means leave" - Brexit Betrayal march Marchers pass a sign to "Cuckoo Land" in Easington Getty "Leave means leave" - Brexit Betrayal march Marchers plod on near Grangetown, Tyne and Wear Getty "Leave means leave" - Brexit Betrayal march A marcher holds up a blue passport as the march passes Grangetown, Tyne and Wear Getty "Leave means leave" - Brexit Betrayal march Nigel Farage poses for a photo in a pub in Hartlepool Reuters "Leave means leave" - Brexit Betrayal march Nigel Farage pays his respects to Tommy, the statue of a First World War soldier in Seaham, County Durham Getty "Leave means leave" - Brexit Betrayal march An anti-Brexit van has been graffitied in Sunderland on the Brexit Betrayal march Getty "Leave means leave" - Brexit Betrayal march A marcher carries a Union flag reading "Storm Brexit" in Sunderland Getty "Leave means leave" - Brexit Betrayal march A couple push a Save Our Sovereignty trolley through a tunnel in Easington, County Durham during the Brexit Betrayal march Getty "Leave means leave" - Brexit Betrayal march Nigel Farage enjoys a pint with fellow marchers in Hartlepool Getty "Leave means leave" - Brexit Betrayal march A pro-European counter-marcher lets off a smoke grenade with the colours of the EU flag Getty "Leave means leave" - Brexit Betrayal march Nigel Farage leads the march in Easington Getty "Leave means leave" - Brexit Betrayal march Marchers plod on near Easington Getty "Leave means leave" - Brexit Betrayal march Nigel Farage takes part in the Brexit Betrayal march Getty "Leave means leave" - Brexit Betrayal march Nigel Farage poses on the top deck of the Brexit Betrayal bus in Seaham Getty

The so-called “flextension” would also give the UK the option of a longer delay if needed, but only on the condition of deciding to join in European Parliament elections before April 12.

One EU official said: "March 29th is over. As of tonight, April 12th is the new March 29th."

Speaking after the agreement was struck, European Council president Donald Tusk said Ms May “accepts the extension scenarios”.

He added: “Frankly speaking I was really sad before our meeting – now I am much more optimistic.”

European Commission president Jean-Claude Juncker added: “This closes and completes the full package. There’s no more we can give. We’re hopeful that the agreement will be adopted by the House of Commons.”

"I hope we can all agree that we are at the moment of decision," Theresa May said at a press conference in the early hours of the morning.

"It gives us the opportunity, MPs next week, to look at the choices that clearly face them: we can leave with a deal, in an orderly manner, have that extension until 22 May - or, if we don't get that deal through, if we don't get that vote through then before 12 April we have to come forward with another plan, and if that plan means a further extension it means standing in those European Parliamentary elections."

At the start of the mammoth Brussels drafting session Theresa May took questions from EU leaders about her Brexit strategy, with diplomats privy to discussions describing her responses as unconvincing and wooden.

According to several accounts, the prime minister was unable to answer what would happen if she could not pass the vote in parliament and had no apparent plan B, spooking her fellow leaders.

After Ms May was sent out of the room, the 27 leaders discussed options for an extension that included dates in April, May, and delays until the end of the year. Both conditional and unconditional extensions were considered by EU leaders.

Discussions and drafting of the new plans spilled over into a late night dinner, with a planned meeting about China-EU relations pushed back until Friday. Planned press conferences by Theresa May, Donald Tusk and Jean-Claude Juncker were postponed until just before midnight.

Leaders ultimately agreed a text which read: “The European Council agrees to extension until 22 May, provided the withdrawal agreement is approved by the House of Commons next week. If the withdrawal agreement is not approved by the House of Commons next week, the European Council agrees to an extension until 12 April and expects UK to indicate a way forward before this date for consideration by EUCO.”

Arriving at the summit in the afternoon Theresa May said the prospect of a delay was “a matter of regret” for her. She also confirmed she would seek an extension until 30 June.

Support free-thinking journalism and attend Independent events

On the way into the meeting Emmanuel Macron had perhaps the starkest warning of Ms May’s European counterparts, telling reporters: “We have to be clear: we can discuss and agree an extension if it is a technical extension in the case of a ‘yes’ vote. In the case of a ‘no’ vote, it will guide everybody to a no deal, for sure.”

The French president said that a longer delay would require “a deep political change” in the UK, adding: “We cannot have a long-lasting situation where there is no visibility, no purpose, no political majority.”