Boris Johnson was re-elected as Mayor of London in a surprisingly narrow victory that saw him beat rival Ken Livingstone.
The Conservative polled 1,054,811 to the Labour candidate's 992,273 following a deeply personal and bitter campaign battle that saw the two men clash furiously in public and in private.
Mr Johnson vowed to continue "fighting for a good deal for Londoners" from government as he thanked voters for giving him a "new chance".
The Mayor outperformed his party, which suffered a significant drubbing nationally, but failed to secure the massive win predicted by polls over recent days that had put him as far as 12 points ahead.
Early results in the contest also suggested the incumbent was significantly in the lead and even senior Labour figures conceded the Tory was poised to win. But later count declarations saw the gap reduce, fuelling speculation Mr Johnson's victory was not the done deal that had been tipped.
No candidate won enough votes in the first round to secure victory, meaning second preferences had to be counted.
Labour secured eight of the London Assembly's 14 first-past-the-post constituencies, gaining two from the Tories, which left them with six.
Liberal Democrat Brian Paddick was pushed into a humiliating fourth place after polling 91,774 votes, compared to the 98,913 secured by the Greens' Jenny Jones.
Political newcomer, Independent Siobhan Benita, took fifth with 83,914.
Ukip's Lawrence James Webb polled 43,274 while the British National Party's Carlos Cortiglia came last with 28,751.
Counting, which is carried out electronically, was dogged by delays, pushing back the result back significantly on original predictions that it would be announced in the early evening.
They included a power cut at Alexandra Palace as well as the reprocessing of two mislaid batches of ballot papers in the Brent and Harrow constituency.
In his victory speech Mr Johnson admitted it had been a "long and gruelling" campaign.
The Conservative went on to take a swipe at his Labour rival - during the campaign he had rowed with him in a lift and called him a f****** liar - saying last time round he had said complimentary things about Mr Livingstone adding: "Fat lot of good it did me."
He added sarcastically: "Of all the left-wing politicians I can think of your long period in office... you have been the most creative and the most original.
"And, if only you will promise not to stand again, I much look forward to having that non-taxpayer funded drink that we have so far not managed to fit into our diaries."
He pledged to make sure Londoners, especially young people in the city, were "ready to take the jobs" that are being created.
Mr Johnson said he wanted to thank those who voted for him, those who did not and those who thought about it.
"I want to thank all of you for giving me a new chance and a new mandate to take us forward."
Mr Livingstone dramatically announced his retirement from electoral politics in his speech accepting defeat immediately after the result was declared.
"This is my last election," he told fellow-candidates and supporters at City Hall. "Forty-one years ago almost to the day, I won my first election on a manifesto promising to build good council housing and introduce a free bus pass for pensioners.
"Now I've lived long enough to get one myself. I didn't think I necessarily would at the time.
"And since then, I've won 11 more elections and lost three. But the one I most regret losing is this. This is the defeat I most regret, because these are the worst times for 80 years, and Londoners needed a mayor to get them through this very difficult period by cutting fares, by cutting energy prices and putting people back to work building good council homes.
"I am sincerely sorry to those Londoners who desperately wanted us to win that I failed to do that and they will continue to bear the pain of this recession without any help from here in City Hall."
Mr Livingstone suggested that Mr Johnson may have sealed the succession as next Conservative leader with his victory today.
Joking that the mayoral result might have spoiled David Cameron's supper, the veteran Labour candidate said: "The real story tonight is that under Ed Miliband we have won in every part of the country.
"I want to congratulate Boris on his personal victory. Whilst Cameron and Osborne are dragging the Tory Party down to defeat in the rest of Britain, not only have you won another term, but I suspect this result has settled the question of the next Tory leadership election."
Mr Livingstone hailed Jenny Jones' third place as a "huge breakthrough for the Green Party", and said that Lib Dem Brian Paddick's fourth place was not his fault, adding: "I suspect that nice Mr Clegg."
Thanking supporters, activists and Mr Miliband for their help with a "gruelling" campaign, he said: "I am truly sorry I couldn't pull this victory off, but I am incredibly proud of our team and its incredibly hard work."
Mr Livingstone said he wondered whether the "negativity and smears" of the London campaign had influenced cities around England which rejected directly-elected mayors in referendums.
And he gave a warning for the future unless Labour wins back power in 2015: "Today's teenagers are the first generation of English men and women who face a worse prospect than their parents.
"This is because the aggressive free-market agenda set by the Tory Party 30 years ago has failed to deliver the sound economy they promised. Osborne pushing us back into a double-dip recession merely confirms it."
He added: "London is the most amazing city but our children must be able to find homes and jobs in it, as they must in the rest of Britain.
"The gains that Labour has made today are a big stride towards achieving that under Ed Miliband at the next general election."