Brussels, Belgium (CNN) The European Union has agreed a delay to the tortuous Brexit process that avoids the UK crashing out without a deal and throws one last lifeline to the beleaguered British Prime Minister, Theresa May.

After hours of negotiations that stretched late into the night in Brussels, the EU rejected May's proposal for a Brexit delay and imposed their own, two-part timetable.

The revised deal was agreed after a tense summit at which May failed to convince EU leaders that she could persuade British lawmakers to pass her overall Withdrawal Agreement next week and therefore avoid a no-deal Brexit on March 29.

Under the EU's plan, if the House of Commons passes the divorce deal, Britain will leave the EU on May 22. But if May's ill-starred agreement is once again rejected, the UK will be get an unconditional Brexit delay until April 12 to bring new proposals for a way out of the impasse.

In that scenario, if the UK agreed to take part in European Parliament elections in May, the possibility would be open for a further extension of several months.

British Prime Minister Theresa May speaks in Brussels.

Read More