Alex Salmond yesterday staked his claim to become Scotland's next First Minister as the SNP became the largest party at Holyrood.

The historic achievement, which ended 50 years of Labour dominance in Scotland, was achieved by a margin of only one MSP. It left the future of Scottish government on a knife-edge, and Mr Salmond with the initiative.

However, neither the SNP nor Labour can rely on any single other coalition partner to reach the 65 votes needed for a majority administration after results knocked back the smaller parties in a day of tense waits and upsets.

Just before the much-delayed counting process was finally completed, leaving the SNP with 47 seats to Labour's 46, Mr Salmond declared: "Scotland has changed for good and for ever. There may well be Labour governments and Labour First Ministers in the decades to come, but never again will we see the Labour Party assume that it has a divine right to rule Scotland."

The Scottish Labour leadership of Jack McConnell is now in doubt, but having lost only four seats, there is still a chance he will remain as First Minister. Mr McConnell said yesterday he would "keep all options open" and that he would not rush into hasty coalition decisions.

He said: "I have not spent the last five-and-a-half years of my life as First Minister building up Scotland and improving this country to make a snap decision this weekend about the future of our country. It is right and proper this weekend that I and my party reflect on how best to take forward our priorities in government and the parliament again."

As well as the single-seat advantage, the SNP beat Labour in share of the vote on both constituency and list ballots: around 33 to 32% and 31 to 29%, although that represented a difference of only about 16,000 on the constituency vote. The total turnout was estimated at 51.8%, ahead of 2003.

Mr Salmond insisted the electorate had opted for change, and that Labour now had "no moral authority left to govern Scotland", adding: "Scotland has chosen a new political path This is a historic moment - a 50-year storm.

"We will lead with humility but also with passion. We will lead with verve and imagination but also always mindful that we serve the people - all of the people of this ancient and proud nation."

The Holyrood result was part of a pattern of Labour setbacks across England and Wales, posing particular problems for Gordon Brown, as the likely next Prime Minister, in trying to handle a Salmond administration at Holyrood.

It was accompanied by radical changes to the political complexion of Scotland's local authorities, with Labour retaining an overall majority in Glasgow council but falling short of that in former strongholds, including South Lanarkshire.

Yet the results were partly overshadowed by the counting chaos, caused mainly by changes to ballot papers and the voting system. Computer problems involving the new electronic scanning machines led to final results being delayed until nearly 6pm yesterday.

That followed an estimated 100,000 ballot papers being rejected by returning officers for being unclear or blank, in some constituencies representing a bigger number of voters than the majority. The Electoral Commission yesterday promised an urgent inquiry, and Mr Salmond said it should be a judicial investigation.

Mr McConnell said: "It is clear that the arrangements for the conduct of the election were unsatisfactory."

"I want to say on behalf of my party that lessons need to be learnt, lessons will be learnt, but today might not be the day to allocate blame. If action is required, action will be taken."

Annabel Goldie, the leader of the Scottish Conservatives, said the voting problems had been "a catalogue of disasters".

She said: "As we predicted, the number of spoiled ballot papers has increased. Responsibility for this sorry mess lies fairly and squarely with the Lib-Lab pact."

Nicol Stephen, the LibDem leader, said: "I always knew that there could be issues with the electronic counting system on this, its first ever use, but I never expected the problems to be on this sort of scale."

Plans to introduce electronic counting in Northern Ireland Assembly elections have now been shelved as a result of the fiasco.

Douglas Bain, the province's chief electoral officer, was in Glasgow to observe how the system worked. He said yesterday: "There have been a number of problems, of which the problems with e-counting have been one.

"I'm not going to do anything which takes any risk with the democratic process in Northern Ireland. The people of Northern Ireland are confident in the current arrangement and whatever the reality, they now have the perception that e-counting doesn't work."

As the dust finally settled last night, the SNP's tally of seats had risen by 20 to 47 MSPs, out of a total 129. Labour was down four to 46. Tories and LibDems were both down by one seat each, to 17 and 16.

The Socialist parties were wiped out and the independent voices such as the health campaigner Jean Turner silenced. Indeed smaller parties secured only three seats; two for Greens and Independent Margo MacDonald in Lothian.

Two ministers lost out to the SNP as seats changed hands; Labour's Deputy Enterprise Minister Allan Wilson in Cunninghame North, and LibDem Deputy Finance Minister George Lyon was defeated in Argyll and Bute.

The SNP strategy of winning 20 constituencies did not work as planned, with the party failing to win marginal seats it had needed, including Aberdeen Central, Cumbernauld and Kilsyth and Tweeddale, Ettrick and Lauderdale. However, Mr Salmond and his deputy, Nicola Sturgeon, both gained seats, in Gordon and Glasgow Govan, while the SNP won some seats unexpectedly, including Stirling and Edinburgh East and Musselburgh.

Yesterday, the SNP staged a presidential-style statement by Mr Salmond before the final result was clear, seeking to build momentum while Labour and LibDems stalled for time. Their MSP groups meet today to discuss options.