The Scottish National Party leader said she knew "in my head and in my heart" this was the right time to step down.
Ms Sturgeon said she would remain in office until her successor was elected.
She is the longest-serving first minister and the first woman to hold the position.
Ms Sturgeon insisted her resignation was not in response to the "latest period of pressure", which has included controversies over gender reforms, trans prisoners and the strategy on independence.
She acknowledged there had been "choppy waters", but said her decision had come from "a deeper and longer-term assessment".
"Since the very first moment in the job, I have believed that part of serving well would be to know, almost instinctively, when the time is right to make way for someone else," she said.
"And when that time came, to have the courage to do so, even if many across the country, and in my party, might feel it too soon.
"In my head and in my heart I know that time is now. That it is right for me, for my party and for the country.
"And so today I am announcing my intention to step down as first minister and leader of my party."
Prime Minister Rishi Sunak paid tribute to Ms Sturgeon "for her long-standing public service".
He said they "didn't agree on everything" but had successfully worked together on freeports.
Scottish Conservative leader Douglas Ross MSP said: "Whatever our differences, it is right we recognise that political leadership is always demanding and takes its toll on a person and their family."
But he added that Ms Sturgeon had "presided over a decade of division and decay in Scotland".
Former first minister and SNP leader Alex Salmond, who now leads the Alba party, said he felt for Ms Sturgeon personally - but that there was no obvious successor and no clear strategy for independence.
Deputy First Minister John Swinney said he was "very sorry" at the first minister's decision but "completely understands" her reasons.
"It's obviously been a shock to all of us, a shock to the SNP family and shock to the country as well," he said.
The SNP's Westminster leader Stephen Flynn said Ms Sturgeon had been an "outstanding political leader".
"She has taken support for independence to record levels and won every national election, by margins other parties could only wish for," he said.
Ms Sturgeon has been a member of the Scottish Parliament since 1999, and became the deputy leader of the SNP in 2004.
She has been first minister since November 2014, when she took over from Alex Salmond after the defeat in the independence referendum.
Ms Sturgeon has led the SNP to a series of election victories at UK, Scottish and local level.
Last year the UK Supreme Court ruled that Holyrood did not have the power to stage another independence referendum - a move which has been blocked by the UK government.
Ms Sturgeon wants the SNP to fight the next general election as a de facto referendum, but there has been some opposition to the plan within the SNP.
In addition, recent months have seen controversies over gender reforms, which have been blocked by the UK government; a teachers' strike; and rows over the management of transgender prisoners.