Labour suffered heavy losses at the hands of the SNP, with the Tories defying opinion polls to secure a House of Commons majority.
In a speech in London, Mr Miliband said it was "time for someone else" to take over the leadership and that he was "truly sorry" he did not succeed.
Shadow chancellor Ed Balls was among the party's big-name casualties.
It also lost its election campaign chief Douglas Alexander and its leader in Scotland Jim Murphy.
Mr Miliband was applauded by staff as he arrived at Labour headquarters in central London.
He confirmed deputy leader Harriet Harman would be interim leader.
"I joined this party aged 17," he said. "I never dreamed I'd lead it."
He may have served in Gordon Brown's cabinet, but few people outside politics had heard of Ed Miliband before he was elected leader of the Labour Party in 2010, a post he has now relinquished in the wake of Labour's election defeat.
He had spent much of the first 40 years of his life in the shadow of his older brother David, the former foreign secretary.
He did the same course - Philosophy, Politics and Economics - at Oxford University, at the same college, and followed David into a similar backroom role in the Labour Party, albeit on different sides of the Tony Blair/Gordon Brown divide. The two even lived in neighbouring flats in the same building for a while.
In full: The Ed Miliband Story
He joked that he would spending his time "reacquainting" himself with his wife and children, thanked the public for the "selfies" and - in a reference to an online trend of teenage fans - "the most unlikely cult of the 21st century - milifandom".
Mr Miliband said he had done his best for five years, and that it was "not simply leadership that achieves change".
"I will never give up on fighting for the Britain that I believe in," he said.
He urged supporters not to "mourn" the defeat.
"We have come back before and this party will come back again," he added.
Speaking earlier after retaining his Doncaster North seat, Mr Miliband said his party had been overwhelmed by a "surge of nationalism".
Ms Harman confirmed she would step down as deputy leader once the new leadership is in place.
Labour MP Tom Watson - the party's former campaign co-ordinator - confirmed that he would consider running to replace her.
"I've always thought that the deputy leader role is the campaigning role," he told BBC News.
"We've got a mayoral election in Tower Hamlets to fight in six weeks' time. Who knows, we might even have a by-election for London mayor.
"So this party has got to keep campaigning whilst we try and understand what's gone on in the general election."
Mr Balls lost his Morley and Outwood seat to Conservative candidate Andrea Jenkyns by 422 votes.
"Any personal disappointment I have at this result is as nothing compared to the sense of sorrow I have at the result Labour has achieved across the UK, and the sense of concern I have about the future," he said.
Mr Balls said questions would arise about the future of the United Kingdom and Britain's position in Europe over the next five years.
Labour also lost previous leader Gordon Brown's former constituency to the SNP as the nationalist party almost swept the board in Scotland.
Mr Alexander lost his seat to a 20-year-old student after a massive 26.9% swing from Labour to the SNP in Paisley and Renfrewshire South.
Conceding defeat, Mr Murphy said: "The party that has traditionally been the tireless champion of the underdog now finds itself in the position of being the underdog.
"Scotland needs a strong Labour Party and our fight-back starts tomorrow morning."
Former Labour Home Secretary Lord Reid told the BBC "changing the captain" would not necessarily improve Labour's electoral prospects.
"They (the public) thought we were on the wrong side of all the major arguments - our economic competence, on the question of creating wealth rather than just distributing wealth, on the question of immigration, on the question of reform of the public services," he said.
Another Labour peer, former First Minister Lord McConnell, said his party had experienced a "catastrophic night".
"I think the Labour strategy for this election was always going to end up in this situation," he said.
"The idea that we could poll between 30 and 35% and pull off a victory was not going to work."
Ed Miliband has stepped down as Labour leader after his party's disappointing general election showing.