Julia Gillard's prime ministership must have flashed before her eyes in the early hours of Tuesday morning.
In a night of high drama, she came dangerously close to precipitating a full-blown crisis that could have brought her leadership to a premature end.
The Gillard government was pushed to the brink over the Prime Minister's insistence that Australia vote against Palestine's bid to upgrade its status at the UN. Just minutes before the caucus meeting, Foreign Minister Bob Carr stood in Gillard's office and told her, eyeball to eyeball, to change her mind or she faced a humiliating defeat.
He pleaded with her to back an abstention on the UN General Assembly motion to recognise Palestine as a non-member state observer.
In the end, Gillard relented and a crisis was averted, but only narrowly.
RECOMMENDED COVERAGE
ALP pathetic for failing to vote: Howard
Labor's UN move stokes Jewish anger
Gillard rolled on Palestine
It came after a series of dramatic meetings that tested loyalties and long-standing fealty to Gillard's embattled leadership.
At one point, sources suggest, Gillard considered the unprecedented step of calling a meeting of the full ministry and parliamentary secretaries -- 42 MPs and senators -- to bind them to her position in a full meeting of 102 caucus members.
Even the attempt to coral the executive into supporting a view an overwhelming number of the cabinet and the caucus opposed would have finished Gillard's prime ministership.
Several ministers and backbenchers had been warning Gillard for weeks that the position on the UN vote, slated for Friday, needed to be finalised in order to instruct the ambassador to the UN, Gary Quinlan, on what to do.
They were seized by the dramatic change in the caucus on the Israel-Palestine issue, with several factors that have been slowly building within Labor -- Israel's settlement policy, increasing violence by settlers against Palestinians and a right-wing Israeli prime minister who backed Mitt Romney over Barack Obama.
There is concern both Israel and the Palestinian Authority are stalling on a two-state solution and that the outcome of the UN vote could positively energise those discussions.
And, critically, there is the growing Muslim and Christian make-up of several key western Sydney Labor seats, which have exposed MPs to different points of view on the Middle East.
Some sections of the party suggest Victorian Labor is too close to the Israel lobby and does not fully understand the underlying changes in Sydney's outer suburbs.
However, one Victorian minister said: "How are we going to solve Labor's challenges in western Sydney by the way we vote at the UN?"
Before the cabinet meeting late on Monday, Gillard met with senior ministers for two hours to discuss the UN vote. Carr sketched out the foreign policy argument for not opposing the Palestinian motion that he believed was in Australia's interests.
Environment Minister Tony Burke, holding a seat in southwest Sydney, explained the shift in the community he had been feeling on this issue for a long time.
Wayne Swan, Defence Minister Stephen Smith, Communications Minister Stephen Conroy and Transport Minister Anthony Albanese also attended.
Before this meeting, Gillard made an extraordinary request to the NSW Right faction convenor and chief government whip, Joel Fitzgibbon. She wanted him to bind the Right behind her position. Fitzgibbon refused.
Meanwhile, former prime minister Bob Hawke, a long-time ardent supporter of Israel, was arguing behind the scenes for Australia not to oppose the motion on Palestine. So had his foreign minister, Gareth Evans, who warned Labor MPs and senators not to be "on the wrong side of history".
In cabinet, Gillard introduced the topic and stated her position. Albanese, Burke, Trade Minister Craig Emerson, Arts Minister Simon Crean, Resources Minister Martin Ferguson, Industry Minister Greg Combet, School Education Minister Peter Garrett and Immigration Minister Chris Bowen all spoke against it.
Conroy and Workplace Relations Minister Bill Shorten, both of the Victorian Right, indicated support for Gillard's position.
Carr also spoke, and made the case for not opposing the UN motion. Some ministers regard this as breaking his word to Gillard not to speak. Others say he had no choice but to offer his view, given the spirited debate.
At the end of the meeting, Gillard summed up the debate and cabinet agreed to back her judgment, given she is Prime Minister. After what one minister described as "a barrage of opposition", the meeting broke up in stunned amazement. Gillard remained steadfast. Few can understand why she so trenchantly held the view that it must be a no vote. Even her closest supporters were telling her it was a lost cause in caucus. After cabinet finished, a cabal of ministers met to discuss strategy and started contacting caucus members. The details of the cabinet meeting quickly reverberated around Parliament House. A motion to support the Palestinian bid was on the agenda for caucus the next morning and was likely to be supported.
Parliamentary Secretary for Climate Change Mark Dreyfus, from the Victorian Right, urged Fitzgibbon to have the national Right bind its MPs and senators in support of Gillard's position.
Fitzgibbon rebuffed Dreyfus several times on Monday and again on Tuesday.
Gillard met with key members of the Left and Right separately before the caucus meeting on Tuesday morning. She also met again with several ministers.
The Treasurer alerted her to the danger that lay ahead. Sources say it was not until then that Gillard was fully cognisant of the weight of numbers against her. Until then, one observer says, "Gillard was all at sea."
Backbench MP Andrew Leigh had before parliament a motion urging a yes vote, to recognise Palestine as a non-member state observer at the UN. Leigh was reluctant to back away from it. Part of the deal reached with Gillard to support an abstention vote required Leigh to withdraw the motion, which he did.
This was not a secret back-door attempt to white-ant a prime minister; it was conducted in full view to get Gillard to make what MPs believe is the right policy decision in Australia's interests.
Carr worked as craftily as he had ever done as NSW premier to see his view prevail. Some say the vigour with which he pursued this has put him offside with some in the party. Others say it marks his arrival as a serious political player in Canberra.
Carr will not be critical of Gillard's leadership. He believes she made the right call in the end.
Moreover, along with eight other ministers, he saved Gillard's neck. As one familiar with the discussions said yesterday: "If the caucus resolution on abstention didn't go under her feet, she would have gone under the ice."