Boris Johnson has won a second term as London mayor, beating Labour rival Ken Livingstone by 3%, after a far closer contest than expected.
Mr Johnson won on second preference votes after failing to gain more than 50% in the first round.
He bucked the national trend after heavy Tory losses elsewhere.
Lib Dem Brian Paddick saw his vote collapse and he was beaten into fourth place by Green Jenny Jones, with independent Siobhan Benita fifth.
Mr Johnson's victory comes after a dismal night at the polls for Conservatives across England, Scotland and Wales, as Labour seized control of 32 councils.
Labour also saw a significant boost in its vote across London in the Assembly elections - but many of the party's voters appear to have shunned Ken Livingstone when it came to choosing a mayor.
In other developments:
Labour gained 823 councillors nationally, as the Tories lost 405 and the Lib Dems 336
Labour had a projected 38% national share of the vote, up three points, the Tories down four on 31% and the Lib Dems unchanged on 16%
The Lib Dems were the big losers in Scotland, where Labour and the Scottish National Party made big gains
Voters in Birmingham, Sheffield, Newcastle, Wakefield, Manchester, Nottingham, Bradford, Leeds and Coventry reject the mayoral system - but Bristol votes in favour and Doncaster votes to keep theirs
Labour have made substantial gains in Wales, including taking Cardiff
Mr Johnson gained 44% of first preference votes, to Ken Livingstone's 40.3%. After second preferences came into play, Mr Johnson gained a total of 1,054,811 votes, or 51.5%, to the Labour candidate's 48.5% - making it an even closer contest than in 2008.
In his victory speech, Mr Johnson vowed to fight for a "good deal for Londoners from the government that will help us deliver prosperity for everybody in this city".
And he added: "I will dedicate myself to making sure that Londoners and above all, young Londoners, are ready to take the jobs that this amazing city creates."
Conservative Party co-chair Baroness Warsi described the win as "historic" and said it was a "testament to the way he has connected with Londoners".
Mr Johnson outperformed his party but failed to secure the massive win predicted by some opinion polls - and at one stage as the count was delayed it looked as if the Labour candidate might overtake him.
Mr Livingstone announced his apparent retirement from front-line politics in his speech, saying "this will be my last election".
He said: "I am truly sorry that we could not pull this victory off."
He also took a swipe at parts of the media and the "negativity and the smears that dominated this election".
Of his opponent, with whom he clashed a number of times during the campaign, he said: "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."
Labour's London-wide Assembly vote was up 14.3% on 2008, while the Conservatives were down 4.7%.
The party secured eight of the London Assembly's 14 first-past-the-post constituencies, gaining two from the Tories, which left them with six.
The 38.1% turnout in London was down 6.7% on 2008 when Mr Johnson and Mr Livingstone last went head-to-head in the race for City Hall.
To cap a dreadful night at the polls for the Liberal Democrats, mayoral candidate Brian Paddick lost more than half of his 2008 vote.
Independent Siobhan Benita, a political newcomer, was the surprise package of the night, threatening at one point to come third ahead of Mr Paddick and the Green's Jenny Jones.
She has told the BBC she plans to stand again in 2016, adding that people were "disillusioned with party politics" and wanted "a new type of public leader".
UKIP's hopes of returning to the London Assembly appear to have been dashed - but the party blamed an administrative blunder by their officials, which led to candidates being listed as "Fresh choice for London" rather than UKIP.