Kevin Rudd has ousted Prime Minister Julia Gillard as leader of Australia’s Labor Party.
He won by 57 votes to 45, in a leadership ballot of Labor lawmakers.
The change comes ahead of a general election due in September, which polls suggest Labor is set to lose.
This is the latest twist in a long and bitter rivalry between the two politicians – but it could be the last as Ms Gillard has said she will now leave politics.
“I will not re-contest the federal electorate… at the forthcoming election,” said Ms Gillard, Australia’s first female prime minister.
“What I am absolutely confident of is it will be easier for the next woman and the woman after that and the woman after that, and I’m proud of that,” she added.
Despite their bitter rivalry, Mr Rudd praised his predecessor, describing her as a woman of extraordinary intelligence, with great strength and energy.
“Julia, as prime minister and prior to that as deputy prime minister, has achieved much under the difficult circumstances of a minority government,” he told a news conference after his victory.
Mr Rudd is more popular with voters than Ms Gillard, and many believe Labor will perform better in the election under him.
Meanwhile, opposition leader Tony Abbott called on Mr Rudd to name an election date, arguing that it should be sooner than 14 September – the date set by Ms Gillard.
“The Australian people are yearning to make a choice. The Australian people are well and truly over this low and dishonourable parliament,” he told a news conference.
Wednesday’s leadership test was the third faced by Ms Gillard since she took office in 2010. She herself ousted Mr Rudd as prime minister in 2010.
The BBC’s Nick Bryant in Sydney says Mr Rudd has exacted his revenge, after three years of him and his supporters mounting a destabilisation campaign targeted very much at her.
The ballot followed months of speculation over the party’s leadership, and came after a day of drama that saw Mr Rudd’s supporters push for a vote.
Shortly before the vote, a key power-broker, Bill Shorten, switched his support to Mr Rudd, saying Labor stood a better chance in the polls with him.
Many people do not think Mr Rudd will win the election but he may mitigate the losses and shorten the time Labor could spend in opposition if the party loses, our correspondent says.
A poll published earlier this month suggested that three cabinet ministers would lose their seats at the poll under Ms Gillard’s leadership, but would retain their seats if Mr Rudd was leading the party.
The vote makes Mr Rudd the leader of the Labor Party, but not prime minister.
Ms Gillard must write to Governor General Quentin Bryce stating that she is resigning as prime minister before Mr Rudd can be sworn in.
A shake-up in the cabinet is expected following the leadership change.
Deputy Prime Minister Wayne Swan has already quit because of Mr Rudd’s victory. He has been replaced by Rudd ally and transport minister Anthony Albanese.