David Cameron has entered 10 Downing Street as prime minister, returning the Conservative party to power after 13 years.
Cameron accepted the Queen's invitation to form a new government shortly before 8.30pm and minutes later spoke to the country outside Downing Street alongside his wife, Samantha, and announced he will establish a "proper and full" coalition with the Liberal Democrats - the first in British politics since 1945.
It follows four days of intense negotiations between all three main political parties sparked by last week's election which delivered a hung parliament.
Cameron drove into Downing Street to a mixture of cheers and boos before making a sombre speech in front of assembled senior Conservative officials.
He began by paying tribute to the Labour government for handing on a country that is "more open at home and more compassionate abroad," and paid tribute to Gordon Brown's "long record of dedicated service".
"This is going to be hard and difficult work," he said, adding that coalition government "will throw up all sorts of challenges. But together, I believe we can provide the strong and stable government this country needs."
He spoke of "deep and pressing problems: a huge deficit, deep social problems and a political system in need of reform".
He said he wanted to end a culture of "entitlement" in Britain and promote one of responsibilty instead, but promised: "those who can, should, but those who can't we will always help."
He then turned and entered his new home through Number 10's famous door, becoming Britain's youngest prime minister since the Earl of Liverpool in 1812.
Just over an hour earlier, Gordon Brown had stood on the same spot and announced his immediate resignation as PM and party leader in an emotional and dignified speech. He later announced that Harriet Harman, his deputy, will lead the party until an election which is likely to take place either in the summer or early autumn.
"I wish the next prime minister well as he makes the important choices for the future," he said. "Only those who have held the office of prime minister can understand the full weight of its responsibilities as well as its great capacity for good. "I love the job, not for its prestige titles and ceremony – that, I do not love at all – but for its potential to make this country more fair, more green, more democratic."
He gave special stress to thanking the armed forcing, saying: "Our troops represent all that is best in our country." He said he would never forget "all those who have died".
His voice faltering, he thanked his wife "for her unwavering support as well as her love", and thanked his young sons, Fraser and John.
Brown said: "As I leave the second most important job I could ever hold, I cherish the first even more: as a husband and a father."
He ended with a simple "Thank you and goodbye" before leaving with his family for Buckingham Palace.
As he drove away after a short 15 minute audience with the Queen, David Cameron's silver Jaguar headed in the opposite direction, getting stuck briefly in traffic behind a learner driver.
He arrived a couple of minutes later and accepted the Queen's request to form a new government in a protocol known as "kissing hands",
Tonight's historic events followed the breakdown of last-ditch talks between senior Labour figures and the Liberal Democrats aimed at forming a "progressive coalition" to keep Cameron out of Downing Street.
It also brought down the curtain on 13 years of Labour rule and followed four days of intense political wrangling between the three main parties after last week's general election delivered a hung parliament.
If a deal is ratified with the Lib Dems at a meeting of the party's MPs later this evening, it would be the first coalition in British political history since 1945.
Brown's resignation ended a day that had begun with hope among Labour supporters that, despite having come second at the polls, they might be able to continue in power. Senior Labour figures opened formal talks with the Liberal Democrats after Brown announced he would be willing to stand aside as party leader. But the talks foundered quickly, and senior Liberal Democrats then spent most of the day at the Cabinet Office locked in talks with the Conservative negotiating team; Cameron also met Clegg in private for an hour.
The day had begun with a serious-faced Cameron telling reporters outside his west London home: "It is now, I believe, decision time – decision time for the Liberal Democrats. And I hope they make the right decision to give this country the strong, stable government that it badly needs and it badly needs quickly."
Shortly afterwards, Nick Clegg, the Liberal Democrat leader, emerged from his house looking tired after talks with Lib Dem colleagues continued into the small hours.
"We will act, as ever, responsibly," he said. "We will act to try to do our bit to create a stable, good government that the British people deserve."
It is understood that the Lib Dem negotiators, David Laws, Chris Huhne, Danny Alexander and Andrew Stunnell, sensed a negative attitude towards a deal from elements of their Labour counterparts, notably Ed Balls and Ed Miliband. This was even though Ed Miliband told the BBC at lunchtime there had been "a good atmosphere" in discussions. There was also a fear that although Labour negotiators said they were in favour of voting reform, they might not have had the political strength to deliver it.
Shortly after 1.30pm, the balance of power seemed to shift towards the Tories once more when William Hague, who was part of the Conservatives' four-man negotiating team, announced that the Tories were about to return to the Cabinet Office to resume negotiations with the Liberal Democrats.
By mid-afternoon, the Tory leader was seen entering Portcullis House, the MPs' office block, with a smile on his face.
During the afternoon, the Labour health secretary, Andy Burnham, said that he was not in favour of a Lib-Lab deal amid unconfirmed reports that his fellow cabinet ministers Jack Straw, Bob Ainsworth, Liam Byrne and Siddique Khan were also opposed.
The former home secretary David Blunkett said earlier that joining a "coalition of the defeated" would spell electoral disaster for Labour.
Another former home secretary, John Reid, said: "Don't forget we have just had the biggest loss of seats in Labour's history. If we are perceived to be responding to that by ignoring it and by trying to cobble something together that patently isn't in the national interest, then we will face the same thing in the future."