By Ian Dunt
Gordon Brown has quit as prime minister, following the emergence of an expected Liberal Democrat-Conservative pact.
The resignation brings to end three troubled years in No 10, in which Mr Brown has faced down a global financial crisis and innumerable coups against his leadership.
"I wish the next prime minister well as he makes the important choices for the future," Mr Brown said.
"Only those who have held the office of prime minister can understand the full weight of its responsibilities and its great capacity for good.
"I have been privileged to learn much about the very best in human nature and a fair amount too about its frailties - including my own."
Mr Brown said "thank you and goodbye" before walking to a waiting car with his wife to offer his resignation to the Queen.
He spent his last hours as prime minister in Downing Street, with aides and his wife Sarah. Ed Balls, Peter Mandelson, Sue Nye, and Douglas Alexander were present. Tony Blair was reported to have phoned Mr Brown earlier this evening.
Later in the evening, Mr Blair issued this statement: "I spoke to Gordon Brown tonight in a warm conversation that reflected a friendship of almost 30 years' duration.
"I pay tribute to the dignity, courage and leadership he has shown in these last few days and to the quite extraordinary service he has given to our country in 13 years of government as chancellor and prime minister and to the cause of social justice at home and abroad."
Mr Brown's final exit came on a day which began with Labour-Lib Dem talks, which became official yesterday after he revealed them in a surprise statement announcing his intention to step down as Labour leader.
That statement sent shockwaves through British politics, but few people could have predicted that Mr Brown would be making a second resignation statement, this time as prime minister, just over 24 hours later.
Labour's refusal to compromise on its manifesto is believed to have contributed to the swift collapse of talks with Nick Clegg's party. The Lib Dems spent the afternoon in lengthy talks with a Conservative negotiation team led by William Hague. It concluded shortly after Mr Brown's resignation.
The contest for the Labour leadership can take place now that negotiations have ended, but Harriet Harman already appears to have ruled herself out by saying she would like to remain deputy Labour leader.
David Miliband, currently foreign secretary, remains the favourite to succeed Mr Brown, but is expected to face a tough challenge from his brother, energy and climate change secretary Ed.