SYDNEY, Australia — Former Prime Minister Kevin Rudd on Wednesday pulled off one of the most sensational political comebacks in Australian history, ousting in a party vote Prime Minister Julia Gillard, the woman who replaced him as leader of the Labor Party in a 2010 coup.

Mr. Rudd’s victory late Wednesday was followed by the resignation of Ms. Gillard, who had called the surprise vote to head off a challenge from Mr. Rudd’s backers. Much of the momentum to reinstate Mr. Rudd came from a steady drumbeat of polls showing that the party under Ms. Gillard was almost certain to face a catastrophic loss in coming elections.

At a news conference after the vote, Ms. Gillard said she was privileged to have served as the country’s first female prime minister, and proud of her accomplishments despite challenges from within her party as well as from the opposition. “It has not been an easy environment to work in,” she said. “But I am pleased that in this environment, which wasn’t easy, I have prevailed to ensure that this country is made stronger, and smarter, and fairer for the future.”

Mr. Rudd had been derided during his tenure for an authoritarian leadership style. But Ms. Gillard has seen her poll ratings plummet since announcing in January, unusually early, that federal elections would be held in September.