Media playback is unsupported on your device Media caption Election 2015: The story of the Conservative victory

David Cameron has returned to Downing Street with the Tories having defied polls and won the general election.

The Conservatives made gains in England and Wales and are forecast by the BBC to secure 331 seats in the Commons, giving them a slender majority.

Labour leader Ed Miliband said he would stand down on Friday, saying his party must "rebuild" with a new leader.

Lib Dem leader Nick Clegg has also said he will quit, with his party set to be reduced from 57 to eight MPs.

UKIP leader Nigel Farage is also quitting after he failed to win Thanet South, losing by nearly 2,800 votes to the Conservatives.

In other election developments:

The Conservatives have now won the 326 seats needed to form a majority administration, meaning they are able to govern without the need for a coalition or formal agreement with other parties.

Mr Cameron all but declared victory in a speech after being returned as MP for Witney, in which he set out his intention to press ahead with an in/out referendum on Britain's membership of the European Union and to complete the Conservatives' economic plan.

Image copyright Getty Images Image caption David Cameron is having an audience with the Queen later as he begins to form his government

Image copyright AFP Image caption Ed Miliband said he accepted "absolute and total responsibility" for his party's defeat

"My aim remains simple - to govern on the basis of governing for everyone in our United Kingdom," he said.

"I want to bring our country together, our United Kingdom together, not least by implementing as fast as we can the devolution that we rightly promised and came together with other parties to agree both for Wales and for Scotland.

"In short, I want my party, and I hope a government I would like to lead, to reclaim a mantle that we should never have lost - the mantle of One Nation, One United Kingdom. That is how I will govern if I am fortunate enough to form a government in the coming days."

Mr Cameron later returned to Downing Street with his wife Samantha and is now having an audience with the Queen at Buckingham Palace.

Chancellor George Osborne said the Conservatives had been "given a mandate to get on with the work we started five years ago" and would follow the "clear instructions" of the British public.

However, Work and Pensions Secretary Iain Duncan Smith acknowledged that governing with a small majority was difficult.

"Whatever else we now do we keep it simple, we keep it focused and we absolutely stick to our manifesto commitments," he told the BBC.

He said the party would deliver an EU referendum as it was a "red line".

Analysis by Nick Robinson

Not since the fall of Thatcher or the Blair landslide has there been a political moment quite like this one.

Personal triumphs for David Cameron and Nicola Sturgeon will not just reshape British politics but could perhaps reshape the future of the United Kingdom itself.

Bitter disappointment for Ed Miliband and a political disaster for Nick Clegg may lead to both men quitting, and is sure to lead to months of soul searching for their parties as they mourn the loss of some of their most famous faces - felled by a brutal electoral firing squad.

If UKIP's Nigel Farage fails to win his seat, as many expect, he promised too that he would resign. His party amassed millions of votes in England, more than the SNP in Scotland, but they have struggled to convert them into seats.

The future, though, belongs to David Cameron who defied all those - including at times himself - who doubted that he could ever increase his party's support.

Read Nick's analysis in full here

Although it won a number of seats in London, Labour failed to make the headway it wanted in the South of England and the Midlands, failing to take its top target seat, Warwickshire North, back from the Conservatives.

Speaking in London, Mr Miliband said he had phoned David Cameron to congratulate him on his victory.

He said he would step down as leader with immediate effect and that deputy leader Harriet Harman would succeed him pending a leadership contest.

Labour, he said, needed an "open and honest debate about the way forward without constraints".

"I am truly sorry that I did not succeed," he told party supporters. "I have done my best for five years."

Media playback is unsupported on your device Media caption Ed Miliband: ''It is time for someone else to take forward the leadership of this party''

Media playback is unsupported on your device Media caption Nick Clegg: "I must take responsibility and therefore I announce that I will be resigning as leader of the Liberal Democrats''

Media playback is unsupported on your device Media caption Nigel Farage: "Part of me is happier than I have felt for many, many years"

Media playback is unsupported on your device Media caption Ed Miliband reflects on a disappointing night for Labour

Media playback is unsupported on your device Media caption Douglas Alexander spoke after losing his seat to 20-year-old Mhairi Black

Media playback is unsupported on your device Media caption Ed Balls describes "sense of sorrow" at election result

Media playback is unsupported on your device Media caption Mark Reckless: "Today a majority of people in Rochester & Strood have decided to hire someone else"

He added: "Britain needs a strong Labour Party. Britain needs a Labour Party that can rebuild after this defeat. We have come back before and we will come back again."

He added: "Britain needs a strong Labour Party. Britain needs a Labour Party that can rebuild after this defeat. We have come back before and we will come back again."

After his own defeat, one of the most surprising results of the night, Mr Balls said he had a "sense of sorrow" about his party's disappointing performance but he was "confident that Labour would be back" as a "united and determined" political force.

Labour has been hammered in Scotland by the SNP, with Nicola Sturgeon's party seizing 56 of the nation's 59 seats. Jim Murphy, leader of the Scottish Labour Party, and shadow foreign secretary Douglas Alexander both lost their seats to the SNP, which is benefiting from a 27% average swing from Labour.

Conceding defeat, Mr Murphy said it had "proven hard to turn round years of difficulties with the Scottish Labour Party in just five short months".

Mr Clegg said the results were the most "crushing blow" to the Liberal Democrats since they were formed in the late 1980s and a leadership contest would take place in due course to choose his successor.

"This is a very dark hour for our party," he told party supporters in London. "But we cannot allow the values of liberalism to be extinguished overnight. Our party will come back. Our party will win again."

Speaking at the start of the night, the Lib Dem election chief Lord Ashdown told the BBC that he would "publicly eat my hat" if exit polls predicting the party would win only a handful of seats were borne out.

Media playback is unsupported on your device Media caption Former Liberal Democrat leader Paddy Ashdown: "If this exit poll is right, Andrew, I will publicly eat my hat"

Media playback is unsupported on your device Media caption Jeremy Vine reports on the huge swing to SNP in Scotland

Douglas Carswell has held Clacton for UKIP and it could end up in third place in the national vote share but the party failed to make a breakthrough elsewhere, with fellow defector Mark Reckless losing his seat.

Green Party leader Natalie Bennett fell to an expected defeat in Holborn and St Pancras, finishing in third place. But the party appears to have increased its share of the vote, including in some of the big northern cities and retained Brighton Pavilion, which the party won in 2010.

A total of 650 Westminster MPs will be elected, with about 50 million people registered to vote.

There are also more than 9,000 council seats being contested across 279 English local authorities.

Mayors will also be elected in Bedford, Copeland, Leicester, Mansfield, Middlesbrough and Torbay.