The new deadline, which is 31 October, averts the prospect of the UK having to leave the EU without a deal on Friday, as MPs are still deadlocked over a deal.
European Council President Donald Tusk said his “message to British friends” was “please do not waste this time”.
Theresa May, who had wanted a shorter delay, said the UK would still aim to leave the EU as soon as possible.
The UK must now hold European elections in May, or leave on 1 June without a deal.
The prime minister will later make a statement on the Brussels summit to the House of Commons, while talks with the Labour Party, aimed at reaching consensus on how to handle Brexit, are set to continue.
May tweeted, “The choices we now face are stark and the timetable is clear. So we must now press on at pace with our efforts to reach a consensus on a deal that is in the national interest.”
So far, MPs have rejected the withdrawal agreement May reached with other European leaders last year and they have voted against leaving the EU without a deal.
The EU has ruled out any renegotiation of the withdrawal agreement.
Before the summit, the British prime minister had told leaders she wanted to move the UK’s exit date from this Friday to 30 June, with the option of leaving earlier if Parliament ratified her agreement.
She said that, although the delay extends until 31 October, the UK could leave before then if MPs pass her withdrawal deal.
“I know that there is huge frustration from many people that I had to request this extension,” she said. “The UK should have left the EU by now and I sincerely regret the fact that I have not yet been able to persuade Parliament to approve a deal.”
She added, “I do not pretend the next few weeks will be easy, or there is a simple way to break the deadlock in Parliament. However, we have a duty as politicians to find a way to fulfil the democratic decision of the referendum, deliver Brexit and move our country forward. Nothing is more pressing or more vital.”
The PM said the UK would “continue to hold full membership rights and obligations of the EU” during the delay.