Julia Gillard is a class act. I can’t think of any Australian politician, at least in my time, who’s had to put up with so much crap, and done it with such grace.

Forget about policy and ideology for a moment, and think of it just in human terms. She led a minority government, with all the delicate negotiation that entails. She was up against the most intransigent, ruthless opposition imaginable. She faced, right from the get-go, a hostile media, sections of which were entirely prepared not only to misrepresent the facts at every opportunity but to attack her personally in way we’ve never seen before in this country.

Nothing was too nasty for these opponents – these people I have previously called the Nasty Movement. I don’t think it’s partisan to suggest that commentary which attacks a political leader in the crudest possible language, which suggests her father died of shame, which lampoons her genitalia, for God’s sake, and impugns her partner’s sexuality is demeaning not just to Gillard, but to the whole political process.

This extreme nastiness was not restricted to her, either. A significant part of the reason Rob Oakeshott and Tony Windsor announced their decision to leave politics was the unremitting assaults of the shock jocks. Over the past couple of weeks, the parliament has seen an exodus of other good people too, most of them lamenting as they went the decline in Australian public political discourse.

Facebook Twitter Pinterest Tony Windsor announcing his retirement this morning.

But Gillard had to deal not only with the enemy without; she also faced an implacable enemy within. The Liberal party’s secret weapon was Kevin Rudd.

No matter what the government’s achievements – and they were significant – the Gillard government never got a clear run at selling them. Case in point: only hours before the prime minister announced there would be yet another party room contest for the party leadership, her government’s legislation promising comprehensive reform of the national education system passed the Senate.

Rudd, whose ego vastly outweighs his loyalty and integrity, sabotaged his own party from the moment he lost its leadership. Three times Gillard defeated him for the leadership: first, to take his job after his colleagues realised they could no longer cope with his erratic management style; then again, overwhelmingly in a vote in the party Caucus; then again in a contest which his followers called on, only to have him run away from the battle once he knew he could not win.

And after each, he protested loyalty, while privately he went about sowing discord. After the last, Rudd promised there were no circumstances, none at all, in which he would contest the leadership again. He said he would be a team player. He lied. He whispered his treason to any sympathetic Labor party or journalistic ear.

And so, coming into the last sitting week of the 43rd parliament, the word was that it was on yet again. Less than three months before an election, with Labor way behind, the whispering reached a new crescendo. Rudd and his surrogates were marshalling their forces.

There were two days of edgy hiatus, before the excrement hit the fan on Wednesday.

Kevin Rudd and Anthony Albanese emerge from the leadership spill this evening. Photograph: Mike Bowers/The Global Mail

He said he would be a team player. He lied. He whispered his treason to any sympathetic Labor party or journalistic ear.

The day began with Oakeshott and Windsor, jointly announcing they would not contest the election. According to Windsor, they went for a walk the previous night, during which Windsor told Oakeshott he’d decided to pull the pin, and Oakeshott told Windsor the same thing.

They are two honourable men, to whom should go much of the credit for such stability as this minority government has enjoyed. And two players right to the end, for the suggestion was that if Labor lost Gillard as its leader, it might also lose their support on the floor of parliament.

For the next couple of hours, the name of the media game was chasing the independent and minor party players, to see whether Labor could muster the support it needed to keep governing if it changed leader. At this stage, the best that can be said is “maybe”.

But for all this speculation, the fact remained that there was as yet no apparent move to change leader. Late morning and word spread that the Rudd forces had got up a petition in an effort to force a leadership contest. Under party rules, if one-third of Caucus members sign, it forces a ballot.

Ah, but it was devilishly hard to determine whether such a petition existed, let alone divine how many signatories it had. As Gillard later said, it was a bit like the Loch Ness monster in that some people believed it existed, but there was not hard evidence.

Anyway, off we all went to Question Time, half expecting Gillard to do as she did last time and announce in the parliament that she was calling on a leadership vote. But it didn’t happen. Instead, opposition leader Tony Abbott moved to suspend standing orders to debate his motion that “this house calls on the government to end its internal arguments and get on with governing this country.”

His speech was pretty much the stock-standard one he has been giving for three years, flogging again the notion that there was something treacherous in Gillard’s taking of the leadership. That’s rubbish, of course. She remained a loyal team player until it became abundantly clear her party was sick of Rudd and ready to dump him.

Less contentious, though, was Abbott’s assertion that: “The poison inside the Labor Party is paralysing government in this country.”

Yes and no to that one. For, as we noted above, the Gillard government has done pretty well, legislatively, but not at all well in terms of selling its achievements. His motion was defeated by one vote.

Then Question Time was over, and the focus was back on the elusive petition for a leadership spill. Was there a petition? Maybe. Probably. But in the end it didn’t matter, because Gillard called on the contest, a little after 4pm, live on Sky TV. It was, she said, in the “best interests of the nation and the Labor Party for this issue to be resolved”.

Julia Gillard before the vote on party leadership in Parliament House, Canberra. Photograph: Mike Bowers

And this time, she made clear right at the top, it definitely would be permanently resolved. If she lost a ballot, she would leave the parliament. She challenged any other contender – she didn’t name Rudd – to make the same promise. The Caucus would meet at 7pm.

It was a steely, gutsy performance. She looked confident. She had entered politics, she said, to “get things done”. Leadership instability was interfering with that, to the point where someone or other would have to leave the parliament to end that instability.

Then, she went back into the chamber, all poise and smiles, to hear Tony Windsor’s valedictory speech. Meanwhile Rudd held his own presser to confirm that he would stand. His pitch was simple: he’d changed his mind because and was standing “for the sake of the nation”. Without a change of leadership, he said, Labor faced a “catastrophic defeat”.

After that, it was a matter of taking sides, counting numbers. The crucial, Brutus blow for Gillard fell a little after 6.30 when one of the more influential factional players, Bill Shorten, formerly in the Gillard camp, came out in support of Rudd.

He looked and sounded deeply regretful, and why wouldn’t he?

In effect he was agreeing to pay ransom to a hostage taker. His choice was between an honorable contender who had committed to end the instability by leaving the parliament if necessary, and a man prepared to kill his party’s chances if his demands were not met. And in the party room, his demands were, finally met. The vote went 57-45 to Rudd.

Now it just remains to be seen if Rudd’s storied – and to so many who actually know him inexplicable – popularity with electors can do Labor any good.

As the old saying goes, in a democracy people get the government they deserve. Maybe it’s simply the case that Australia deserves a choice between Rudd and Abbott.

• This piece was originally published on The Global Mail