Ms Sturgeon also thanked Baroness Kennedy QC and the working group she chaired for the recent publication of the Misogyny Report, which calls for the establishment of an act to create a new statutory aggravation of misogyny.
The apology from the First Minister is the first formal recognition of the miscarriage of justice that took place under the Witchcraft Act 1563.
In Scotland, an estimated 3,837 people – 84 per cent of whom were women – were tried as witches under the Act, according to the Survey of Scottish Witchcraft.
About 2,500 of those accused were executed and burned.
Speaking at Parliament on International Women's Day, Ms Sturgeon said: “Those who met this fate were not witches, they were people and they were overwhelmingly women.
"This was injustice on a colossal scale, driven at least in part by misogyny in its most literal sense – hatred of women.
“The petition calls for an apology, after all these accusation and persecutions were perpetrated by the state.
"Today, on International Women’s Day, as First Minister on behalf of the Scottish Government, I am choosing to acknowledge that egregious historic injustice and extend a formal posthumous apology to all those accused, convicted, vilified or executed under the Witchcraft Act 1563.”
Ms Sturgeon said it was important to acknowledge injustice no matter how historic.
The First Minister said: "Reckoning with historic injustice is a vital part of building a better country. So too is recognising and writing in to history what has been for too long erased, the experiences and the achievements of women.”
The Witches of Scotland campaign, run by Claire Mitchell and Zoe Venditozzi who sought the apology, has welcomed the report.
They tweeted: “The First @NicolaSturgeon just issued a formal apology to those people, mostly women, convicted under the Witchcraft Act on #InternationalWomensDay2022.
"This is the first formal recognition of this terrible miscarriage of justice @zoevenditozzi @madisonmitchel1.”
Ms Sturgeon said “deep misogyny” continued in society.
She said: "Today, it expresses itself not in claims of witchcraft, but in everyday harassment, online rape threats and sexual violence.”
Addressing the recently published misogyny report, the First Minister said the Scottish Government welcomed the “bold and far-reaching” recommendations and would respond formally as soon as possible.
She said: “On International Women’s Day, let us in this Parliament rededicate ourselves to building a society in which women and girls are safe and in which they feel safe.
"Let us acknowledge and reckon with historic injustice and in doing so let us redouble our work now to consign age-old misogyny to the history book once and for all.”
Her comments come after Baroness Kennedy unveiled the Misogyny – A Human’s Rights Issue report at the Glasgow Women’s Library on Tuesday.
The document calls for the creation of a Misogyny and Criminal Justice (Scotland) Act, which would create a new statutory aggravation of misogyny.
It would also create new offences of stirring up hatred against women and girls to tackle, amongst other things, the threat from incel (involuntary celibates) and other extremist groups.