ED Miliband urged his party to "rise to the challenge" to keep the United Kingdom together as he made his farewell speech, formally announcing his swift resignation.

Speaking before party workers in central London, the outgoing leader, looking drawn and tired, said he was "so sorry" for all those colleagues who had lost their seats; describing the likes of Ed Balls, Jim Murphy, Douglas Alexander and Margaret Curran as "friends and standard-bearers for our party".

In a dignified speech, he thanked Labour activists for pounding the streets and thanked his party for the privilege of being able to lead it, admitting that when he joined Labour at 17, he never imagined he would become its leader.

The party leader said he had "done my best" for the past five years, believing he had changed its culture, so that it could have disagreements without being disagreeable.

"We have come back before and this party will come back again," he declared to cheers and applause. "The fight goes on. Whoever is the leader, the party will be making the case for working people once again."

Mr Miliband confirmed that, after the VE Day commemoration at the Cenotaph in Whitehall this afternoon, he would resign as leader. Harriet Harman, who he described as the best deputy he could have worked with, will take over as caretaker leader for the next few weeks until a new leader is elected.

However, she also announced her plans to resign as the Labour's Deputy Leader once a new top team has been found.  

Saying he was looking forward to spending more time with his family, Mr Miliband thanked people for all the support and the selfies, joking that he had spawned the "most unlikely cult of the 21st century: Milifandom".

On the Union, Mr Miliband said he believed in the UK as the best way to serve all the nation's people. "More unites us than divides us across the UK. " He urged his party to "rise to the challenge to keep our country together", stressing: "Britain needs a strong Labour Party, so that it can have a government that stands up for working people."

He added: "Never give up in the Britain you believe in."

The contest for the leadership is likely to see a contest between Yvette Cooper, the Shadow Home Secretary, Chuka Umunna, the Shadow Business Secretary, and Andy Burnham, the Shadow Health Secretary. Some believe Dan Jarvis, the Shadow Justice Minister and former Army officer, is tipped by some as a fresh face, who could present a new look to Labour.

The new leader is likely to be in place some time next month.

Ms Harman said she would quit the party leadership role when the new leader is appointed.

She said: "With a new leadership team in place, after what has undoubtedly been a serious defeat, the Labour Party will be best placed to be the strong opposition this country needs - defending our NHS and our public services, and fighting for fairness, equality and social justice.

"That determination will be all the fiercer in the face of this Tory government."