The Scottish first minister said she was choosing to acknowledge an "egregious historic injustice".
It is thought 4,000 Scots, most of them women, were accused of breaking the Witchcraft Act between 1563 and 1736.
Ms Sturgeon also told MSPs that parliament could choose to legislate to pardon those convicted under the law.
The Witches of Scotland campaign had urged the government to offer a public apology, saying it would send a "powerful signal".
Witch hunts took place in many countries during that period, but academics say Scotland's execution rate was five times the European average.
Confessions were regularly secured under torture, with those condemned strangled and burned at the stake.
In a statement at Holyrood, the first minister said those accused under the act "were not witches, they were people and they were overwhelmingly women".
She said: "At a time when women were not even allowed to speak as witnesses in a courtroom, they were accused and killed because they were poor, different, vulnerable or in many cases just because they were women.
"It was injustice on a colossal scale, driven at least in part by misogyny in its most literal sense, hatred of women.
"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 of those accused, convicted, vilified or executed under the Witchcraft Act of 1563."
The Witches of Scotland group has been petitioning Holyrood to pardon those convicted under the act, with QC Claire Mitchell saying it would correct as far as possible a "terrible miscarriage of justice".
SNP MSP Natalie Don was already planning a member's bill extending a formal pardon, and Ms Sturgeon noted that parliament may choose to legislate in due course.