FACING a fight for re-election next year, Julia Gillard, Australia's prime minister, was banking on a budget surplus to help rescue her Labor government's declining political fortunes. When Wayne Swan, the treasurer (pictured, above, with Ms Gillard), announced the budget on May 8th, he seemed to have fulfilled her hopes. Declaring that the “surplus years are here”, he said the current financial year's deficit of A$44 billion ($44.8 billion) would become a A$1.5 billion surplus in 2012-13, the first since Labor took power five years ago. He projected the surplus would be five times that amount in three years, more than most people had expected. Yet even as he spoke, Ms Gillard's government was rocked by separate allegations of unseemly behaviour, one against the speaker of the federal parliament and the other against an ex-Labor politician upon whose support she depends. The uproar has undermined her minority government's position in parliament and may yet squash any bounce from the budget.

Thanks largely to investment in mining, Australia has survived the global downturn better than most rich countries. Mining investment over the next three years is expected to be worth 9% of GDP. Australia's ratio of export to import prices is the most favourable in 140 years. But the boom has a flip side. Mining firms have been writing off tax bills against huge investments in new projects, denting government revenue. Mr Swan says A$150 billion in taxes has been written off since the financial crisis.

At the same time, the central bank says the economy last year was slightly weaker than expected; growth is forecast to be 3.25% in the next financial year, good by most people's standards but not Australia's. To achieve a surplus in this climate, Mr Swan has cut about A$17 billion from spending over the next four years. He slashed the defence budget and deferred by a year Australia's plan to raise foreign aid, from 0.35% of gross national income to 0.5% by 2015. He devoted A$22 billion of new spending mainly to helping low- and middle-income earners with education and other living costs. He found the money by dropping the government's plan to cut company tax by a percentage point, a promise linked to a new tax on mining profits.

Mr Swan blamed his decision to ditch the company tax cut on the conservative opposition and the Australian Greens, both of whom had vowed to block it in parliament. But it was really a symbolic gesture calculated to boost the budget's unabashedly political appeal. Many stalwart Labor voters, unhappy with Ms Gillard's leadership and her plans for a carbon tax starting in July, have deserted the government. The budget, which Mr Swan described as “Labor to its bootstraps”, was intended to rescue her government from its sinking poll ratings.

It might indeed help Ms Gillard. But the prime minister had not bargained for the political storms that have burst around Peter Slipper, the speaker, and Craig Thomson, an ex-Labor figure. Late last year she appointed Mr Slipper, a former Liberal, as speaker. The move deprived the opposition of a parliamentary vote, but Mr Slipper had fallen out with his old colleagues. Last month James Ashby, a former staff member of Mr Slipper's, accused him of abusing taxpayer-funded taxi vouchers. He also lodged a civil-court claim against Mr Slipper for alleged sexual harassment.

Mr Thomson is a former senior union official who entered parliament for Labor five years ago. On May 7th, a day before the budget, Fair Work Australia, a workplace tribunal, presented an explosive report after a three-year inquiry. It found that Mr Thomson had “improperly” spent large sums of union money, including on his parliamentary election campaign and on buying “escort services” in Sydney with a union credit card.

Both Mr Slipper and Mr Thomson have denied the allegations. At first, Ms Gillard said they were entitled to a presumption of innocence. As public outrage increased, she changed her tune. On April 29th she said Australians saw a “dark cloud” over parliament. She asked Mr Slipper to stand aside as Speaker until the allegations were resolved. And she asked Mr Thomson to suspend his Labor Party membership. The changes have reduced Ms Gillard's majority to just one. Mr Thomson now sits as an independent, but the government still depends on his vote, for the budget among other things. Unless Ms Gillard can dispel the clouds, the budget's political sunshine may prove short-lived.