Alex Salmond tonight put the Scottish National party on an election footing after his £33bn budget bill was dramatically defeated by the narrowest of margins after a revolt by three opposition parties.
The first minister said he would present his budget for a second time next week, but warned that if it was again rejected by MSPs at Holyrood, his government would have to resign, forcing a major political crisis for the Scottish parliament.
That would require Labour, which is the second largest party in Holyrood with one fewer seat than the SNP's 47, to try and form a ruling coalition. If Labour failed to do so, that would force a fresh election, mid-way through the Scottish parliament's normal four-year term.
Salmond said: "We believe the budget is crucial to the people of Scotland. We believe it's our responsibility to place a budget back before the parliament.
"If the budget can't get through then the government cannot remain in office. Under these circumstances, the normal thing would be to have an election and that's what I would welcome. Of course, other parties could have the option of forming another administration.
"However, it's certainly my view that the people of Scotland would want the opportunity to comment and to elect a new parliament. For that reason, I'm putting the SNP on an election footing tonight."
Salmond's warning was designed to rachet up the pressure on the Scottish Green party and Labour party, who voted with the Liberal Democrats to reject the SNP's budget for 2009-10, to agree a deal with his government on a revised budget.
Salmond lost by only by the single casting vote of the presiding officer, Alex Fergusson, after the SNP secured 64 votes with the support of the Tories and independent MSP Margo MacDonald, tying with the 64 votes commanded by Labour, the Lib Dems and the two Greens.
Protocol requires the presiding officer to vote for the status quo in a dead heat; on this occasion for the current £31bn budget.
The defeat came after Salmond tried but failed to use his personal influence to persuade the Green party leader, Patrick Harvie, to back the budget, in a dramatic intervention outside the parliamentary chamber.
The Greens had demanded an additional £11m to be spent on a free house insulation programme – extra spending that John Swinney, the finance secretary, refused to offer.
Salmond's discomfort increased when Iain Gray, the Scottish Labour leader, raised the prospect of a vote of no confidence against the SNP government – a vote which Labour will demand if Salmond fails to get its revised budget bill passed next month.
Tonight Gray immediately dismissed Salmond's threat of an election: it would require a two-thirds majority of the Scottish parliament to call one.
"Alex Salmond is deluding himself if he thinks he can call an election. The Scottish parliament will call an election, surely he knows the rules."
Swinney tonight tabled a new budget bill immediately after the defeat, and said ministers hoped to have a fresh vote by February 19 at the latest.
Salmond insisted that he was determined to ensure Scotland's councils, health boards and other services had the £1.8bn in additional spending they needed next year.
Swinney had stated his plans were "vital" for the Scottish economy, which was now slipping into recession.
"At a time of serious economic difficulty, we need to get every penny into circulation as quickly as possible," he told MSPs.
The latest official figures for Scotland's GDP showed yesterday that the economy shrank by 0.8% in the last quarter, and was now following the wider UK economy into a fully-fledged slump.
His budget would include £230m in accelerated capital spending brought forward by 12 months from 2010, to invest in hospitals, roads and schools. That accelerated spending would protect 4,000 jobs, he said.
Gray said: "They're in this position as a direct result of their own arrogance and incompetence. They've known for weeks and months what they needed to do in order to change the bill to get support from us potentially and the Greens.
"They took it to a degree of ridiculous brinkmanship, to the extent that we've the first minister of Scotland skulking around the back of the chamber trying to broker a deal; that's pretty shocking."
The collapse of the budget is a severe blow to the SNP. Earlier this month, Swinney and his senior advisers were optimistic they would be able to strike a deal with the Greens, whose two votes, along with the Tories' 16 votes, are essential for the SNP to get a one-vote majority at Holyrood.
Over the last few days, it became clear the Greens believed Swinney's original offer to spend just £10m on a pilot project to provide free loft and cavity wall insulation fell far too short of their £100m-a-year proposals for a 10-year programme.
During tonight's tense debate, MSPs noticed that Harvie was asked out of the chamber by Salmond, in breach of parliamentary protocols that MSPs must stay in the chamber if they want to speak in a debate.
Harvie returned to the chamber and apologised for his absence, then delivered his bombshell: he would vote against the budget unless Swinney raised spending on the insulation programme to £33m - a 50% increase on Swinney's compromise offer of an initial £22m, one-year programme.
"This isn't a last-minute, unrealistic or impossible or unwise demand," Harvie told MSPs. The Greens had sent ministers their very detailed proposals for a £1bn, 10-year free insulation programme on 1 November last year.
The debating chamber of the Scottish Parliament at Holyrood 
The Scottish Parliament has narrowly rejected the Scottish government's proposed £33 billion budget.

The devolved parliament was tied 64-64 on the motion to approve the budget after two Green Party MSPs switched away from backing the minority Scottish National Party (SNP) administration. The Presiding Officer (speaker) of the parliament, Alex Fergusson, used his casting vote to reject the budget. Finance Secretary John Swinney of the SNP announced that he would immediately reintroduce it. The budget had the backing of the Scottish Conservatives.

Green MSPs had sought a £100 million, 10-year home insulation scheme, whilst the Scottish government had offered a smaller pilot scheme. This offer was increased as the vote approached but failed to convince the Greens to back the budget.

If a new budget is not in place by the start of the financial year in April, the current budget will rollover. However, Scottish ministers say this will cause a £1.8 billion cut in spending. 

Scotland's GDP fell by 0.8% in the last quarter.