CANBERRA, Australia (AP) — Australian Prime Minister Julia Gillard was ousted as Labor Party leader Wednesday by her predecessor, Kevin Rudd, in a vote of party lawmakers hoping to avoid a huge defeat in upcoming elections.

The ballot took place three years and two days after Gillard ousted Rudd in a similar internal government showdown to become the country’s first female prime minister. She lacked Rudd’s charisma, and although many Labor lawmakers preferred her style, her deepening unpopularity among voters compelled a majority to seek a change ahead of elections that are set for Sept. 14 but could be held in August.

Australian Prime Minister Julia Gillard Loses Control, Ousted From Leadership Role

Australian Prime Minister Julia Gillard speaks in parliament in Canberra, Australia, Wednesday, June 26, 2013. Supporters of Gillard’s chief intra-party rival are again pushing for a vote to oust the Australian prime minister this week. (AP Photo/Rick Rycroft)

Wednesday’s 57-to-45 vote makes Rudd leader of the party. Governor-General Quentin Bryce could make him prime minister as early as Thursday, but Rudd likely will have to demonstrate that he can command a majority of lawmakers in the House of Representatives.

Labor depends on independents and a minor party for its fragile ruling coalition, but Rudd appeared capable of retaining it after two independent lawmakers who did not back Gillard’s government said they would support his.

The ballot ends a bitter rivalry between Gillard and Rudd that helped create an atmosphere of chaos and disunity. Gillard had survived two previous attempts by Rudd to take over.

Gillard had vowed to quit Parliament at the next election if she lost, and said after the vote that she would fulfill that pledge.

She said she was proud of her government’s achievements, including the introduction of an unpopular carbon tax paid by the biggest industrial polluters. Gillard, who made international headlines for calling opposition leader Tony Abbott a misogynist, also hit back at critics who accused her of playing the gender card.

Because of her tenure, she said, “It will be easier for the next woman and the woman after that and the woman after that. And I’m proud of that.”

After her statement to the press, she went to the governor general to tender her resignation.

Deputy Prime Minister and Treasurer Wayne Swan quit after Rudd’s victory and was replaced by Rudd ally and Transport Minister Anthony Albanese in a second ballot.

Even with Rudd in control, polls suggest that Labor could still be defeated by the conservation opposition led by Tony Abbott. But if that happens, Labor lawmakers hope their losses will be smaller under Rudd than they would have been under Gillard.

Gillard threw open her job to a party leadership ballot Wednesday in response to reports that Rudd’s supporters were pushing for a challenge, and he soon announced he would run against her.

“We are on course for a catastrophic defeat unless there is change,” Rudd said before the ballot. “And so today, I am saying to you, to the people of Australia, I’m seeking to respond to your call that I’ve heard from so many of you to do what I can to prevent Mr. Abbott from becoming prime minister.”

Australian Prime Minister Julia Gillard Loses Control, Ousted From Leadership Role

Kevin Rudd. (Getty Images)

Both Gillard and Rudd had pledged to quit Parliament at the next election if they lost.

The two are in many ways political opposites.

Rudd has a reputation for being a masterful campaigner, but he disappointed as an administrator after taking Labor to a resounding victory in 2007.

A Mandarin-speaking former Beijing diplomat turned state government bureaucrat, he has a nerdy style that endeared him to voters. But colleagues complained he was chaotic, bad-tempered and vicious.

Gillard proved calmer, more efficient and more popular with lawmakers, but she generated extraordinary animosity among voters, partly because she had ousted the prime minister they had elected during his first three-year term.

Rudd had been a popular prime minister who had started sliding in the polls when Gillard, then his deputy, challenged him to a leadership ballot in 2010. He did not contest the ballot when he became aware of the level of Gillard’s support and she became prime minister unopposed. Weeks later, she led Labor to a narrow election victory and formed an unpopular minority government with the support of independent lawmakers and a legislator from the minor Greens party.

Rudd supporters have been accused of undermining Gillard’s leadership from the start and have been blamed for damaging leaks against her. Those leaks partially derailed her 2010 election campaign.

Australian National University political scientist John Wanna, a Labor supporter, said Rudd has been “rewarded for three years of sabotaging the government.”

“Labor’s still going for a train crash” at the election, he said. “Half the Cabinet can’t stand him.”

Australian Prime Minister Julia Gillard Loses Control, Ousted From Leadership Role

Getty Images.

Gillard fended off previous attempts by Rudd to get the prime minister’s job back. In a 2012 ballot of Labor lawmakers, she easily defeated him 71 votes to 31. In February, she threw open her job to a leadership ballot, but Rudd refused to challenge and she remained prime minister.

The fact that Rudd never sat for a portrait to be painted to line the walls of Parliament House, as other former prime ministers had done once they had lost power, fueled speculation that he never abandoned his leadership ambitions.

Follow Becket Adams (@BecketAdams) on Twitter

Featured image Getty Images.