Labour's Gordon Brown has resigned as UK prime minister after three years.
Mr Brown officially tendered his resignation to the Queen at Buckingham Palace, with Conservative leader David Cameron set to succeed him.
Speaking alongside his wife Sarah outside No 10 Downing Street, he said the job had been "a privilege" and wished his successor well.
He has stepped down as Labour leader and will be replaced by deputy Harriet Harman until a successor is elected.
However, Mr Brown will remain as a backbench MP in Parliament.
His decision comes as the Tories and Liberal Democrats are poised to agree a deal to form a government.
'Privilege to serve'
Mr Brown said he had taken the decision to resign after concluding he would not be able to form a government after days of talks between the parties.
In an emotional farewell speech outside No 10, Mr Brown said he had "loved the job" and it had been "a privilege to serve".
"Only those who have held the office of prime minister can understand the full weight of its responsibilities and its great capacity for good," he said.
"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.
"Above all, it was a privilege to serve and, yes, I love the job, not for its prestige, its titles and ceremony, which I do not love at all.
"No, I loved the job for its potential to make this country I love fairer, more tolerant, more green, more democratic, more prosperous and more just - truly a greater Britain.
"In the face of many... challenges up to and including the global financial meltdown, I have always tried to serve, to do my best in the interests of Britain, its values and its people."
Anticipating Mr Cameron's appointment, Mr Brown said: "I wish the next prime minister well as he makes the important choices for the future."
His two young sons joined him and wife Sarah for his brief statement which ended with the words: "Thank you and goodbye."
After leaving the Palace, Mr Brown returned to Labour headquarters to thank party staff. He told them that the election defeat was "his fault and his fault alone".
His resignation follows Thursday's general election in which no party won an overall majority but the Conservatives won the most seats and votes.
Both Labour and the Tories have since been trying to persuade the Lib Dems to join them in a coalition government to run the country.
Mr Brown had previously said he would resign as Labour leader, but stay on as prime minister until September, if Labour could agree a deal with the Lib Dems.
But after this possibility ended, the BBC's Political Editor Nick Robinson said Mr Brown decided he could not form a government and should stand down.
Before making his announcement, Mr Brown consulted with his wife Sarah and close colleagues including Lord Mandelson, Douglas Alexander, Ed Balls and Ed Miliband and also spoke to former prime minister Tony Blair by phone.
Deputy Labour leader Harriet Harman is to become Labour leader until a replacement is elected.
Mr Brown said he would stand by the new leader "loyally and without equivocation".
Labour's ruling National Executive Committee has indicated it wants Mr Brown's successor as leader to be chosen as soon as possible, possibly by the end of July.
Mr Brown succeeded Tony Blair as prime minister in June 2007 after spending ten years as chancellor of the exchequer.