Alex Salmond has resigned as Scotland's First Minister, telling Holyrood he leaves office with "a sense of optimism and confidence".

During a statement at the Scottish Parliament, Mr Salmond said it had been "the privilege of his life" to serve in the role for the past seven-and-a-half years.

He is making way for his deputy Nicola Sturgeon to take over, and he said she will make an "outstanding" First Minister.

Mr Salmond received a standing ovation from MSPs after delivering his final words, before being embraced by Ms Sturgeon.

He told his parliamentary colleagues he was leaving at a time when the Scottish electorate has become energised, empowered and engaged in politics once again following the independence referendum.

He said: "Any parting is tinged with some sorrow, but in this case it is vastly outweighed by a sense of optimism and confidence. Confidence that we will have an outstanding new First Minister. Confidence in the standing and the capability of this chamber, and most of all confidence in the wisdom, talent and potential of the people of Scotland.

"Scotland has changed, changed utterly and much for the better over the 15 years of this Parliament and over the seven years of this Government. But I am happy to say that with every degree of certainty that more change and better days lie ahead for this Parliament and for Scotland."

He added: "Scotland now has the most energised, empowered and informed electorate of any country in Europe. We have a new generation of citizens who understand that their opinion matters, who believe that their voice will be heard and who know that their vote can shape the society they live in.

"For all of us that should be a point of pride, a source of challenge. For me, the sense of generational change has been a factor in deciding the time is right to move on from being First Minister.

"For this Parliament, it should spur us on to become even more accessible, to serve the new expectations of the people.

"For everyone in public life it should inspire us to involve, include and empower the electorate, as we continue the quest to create a more prosperous and more equal Scotland.

"I wish each and every one of you well in pursuit of that endeavour."

Mr Salmond announced his intention to step down just hours after losing the independence referendum in September.

Since then, speculation over Mr Salmond's political future has led to suggestions he will return to Westminster, and he is expected to make his position clear in due course.

He remains MSP for Aberdeenshire East, but he could stand for a seat in the House of Commons at the general election in May.

Ms Sturgeon will be formally appointed as First Minister during a selection process at Holyrood tomorrow, and will be sworn in at the Court of Session in Edinburgh on Thursday.

Mr Salmond reflected on the beginnings of the Scottish Parliament, established in 1999, and on his time as the leader of both a minority and majority government.

"Minority government requires negotiation, to recognise honest disagreement, and then compromise in the public interest," he said.

"Presiding Officer, I have absolutely no idea if my experience in minority government in this place will ever come in handy in another place."

Mr Salmond said MSPs from across the parties had worked together on issues such as climate change, free university education and measures to combat the bedroom tax.

"Most of all, I think about the consistent and often joint endeavour against the headwinds of economic circumstance and austerity to make Scotland a stronger, fairer and more cohesive nation."

Reflecting on the independence referendum, Mr Salmond continued: "We have all just lived through one of the most invigorating, extraordinary debates of the democratic era.

"One of the most impressive of any country, anywhere at any time. It is argued that people everywhere have become disengaged from politics - not in Scotland in 2014.

"It is said that they no longer care about the business of governance - not in Scotland in 2014."

He added: "In the last few months we have watched an electorate passionately engaged in the business of fashioning their own future. I see little evidence that the people of Scotland resented the government pursuing that business with them and for them...

"Scotland has a new sense of political confidence and a new sense of economic confidence.

"They are reinforcing each other, and wherever we are travelling to together as a nation, they are transforming this country for the better.

"That new sense of political confidence, or engagement is the point on which I wish to end."

Labour's Jackie Baillie said she had "sparred, disagreed and fallen out" with the First Minister, but she recognised his commitment to the Parliament and to public service, describing him as "a towering figure in Scottish politics".

"No one of any party is able to deny the First Minister's passion for Scotland or his love of his country," she said.

"The Scottish Parliament and Scottish politics in general need people of talent from whatever political persuasion... and the First Minister's considerable abilities will be missed.

"We know, given his track record, though, that he might just emulate Arnold Schwarzenegger and proclaim he will be back."

Ms Baillie continued: "There is no doubt that the single biggest issue to have dominated his term in office and the lifetime of the Parliament was the referendum campaign.

"Whatever side you were on, no one can deny that it wasn't invigorating.

"Before we are SNP members, before we are Labour members, we are democrats, and to see so many Scots participate was a genuinely heartening experience."

Ms Baillie said Mr Salmond had done the honourable thing following defeat in the referendum by resigning, but she said she was sure people had not heard the last of the First Minister.

"If rumours are true, Alex's colleagues in Westminster will be hearing a lot of him in due course.

"The First Minister has never been lacking in ambition for Scotland, but he moves on now to pastures new, and I do genuinely wish him well in his future career."

Scottish Conservative leader Ruth Davidson described Mr Salmond as "a political Lazarus".

"Railing against a Westminster elite that he's been a part of not once, but twice, and - after May - could return to for a third time," she said.

"But, regardless of whether this is an end, or merely a brief pitstop before Mr Salmond's next lap of the political track, let me today pay tribute, and pass comment, on the First Minister's period in office.

"To have served two decades at the helm, and more than seven years as First Minister, is a feat of enormous stamina, will-power and discipline."

Ms Davidson went on to describe Mr Salmond's record in government as "mixed".

"I do not begrudge him for devoting the Scottish Government's time and energy to campaigning for independence - that was his right and his democratic mandate," she said.

"Rather, in time, I believe questions may be asked over the way in which Mr Salmond fought that campaign.

"There was another case he could have made. He could have accepted and acknowledged the upheaval that separating our United Kingdom would have caused. He could have acknowledged that some things would be worse, at least in the short term."

She added: "I agree with Mr Salmond that this Parliament has indeed become the centre of gravity in Scottish politics. For that too, he and his team deserve our regard.

"He can leave today in the knowledge that he has taken his party from the fringes to a position of enormous strength.

"His leadership has been characterised by a remarkable instinct for the exercise of power. It kept him at the top of his party for two decades, it brought him to the top of Scottish political life, and made him a dominant politician of this era."

Scottish Liberal Democrat leader Willie Rennie compared Mr Salmond with Margaret Thatcher.

"A Marmite figure, with his supporters as passionate as his detractors," he said.

"His lasting legacy will be almost securing independence for Scotland in the biggest democratic experience of all our lifetimes.

"For some it was uplifting and engaging. But, on the other hand, it was far from a universal experience. For too many families, friends and communities, the referendum was divisive.

"He may not wish to accept it, but that will be as much his legacy as all the positive attributes that he would ascribe."

He went on to recognise the personal commitment the First Minister had made.

"I wish him well for the future," he added.

Scottish Green MSP Patrick Harvie criticised Mr Salmond over his Government's dealings with business tycoon Donald Trump before going on to highlight the First Minister's work on climate justice.

On the referendum, he continued: "That urge to change our politics, to build something better, will stay with us, and I have no doubt that Alex Salmond will continue to play a significant part, whether here or elsewhere, in ways that inspire his supporters and infuriate his critics in equal measure."

SNP MSP Stewart Stevenson described Mr Salmond as a formidable politician.

"He is the toughest boss I have ever worked for or with, and the fairest, and a team builder," he said.

Mr Salmond responded with his final words to the chamber as First Minister: "Can I wish every member of this Parliament well, and wish everyone goodbye and good luck."

Earlier, he undertook one of his final official engagements as First Minister with a visit to Heriot-Watt University in Edinburgh.

He unveiled a commemorative stone marking the Scottish Government's commitment to no higher education tuition fees.

The rock is inscribed with the words of the statement made by the First Minister in March 2011: "The rocks will melt with the sun before I allow tuition fees to be imposed on Scottish students."

Mr Salmond also took part in his final meeting of the Cabinet, where he was thanked and applauded by his colleagues. The Cabinet presented him with a personalised blue and white golf bag as a parting gift.

He will remain in post until the start of Holyrood's business tomorrow afternoon, attending his final engagement as First Minister at the Scotland v England football match this evening.