She told the party’s Glasgow conference that an Independence Referendum Bill would be published next week.
It marks the first step to holding a second vote.
The first referendum, which took place on 18 September, 2014, resulted in 55% of voters saying “no” to Scottish independence.
- Follow reaction to the Independence Referendum Bill announcement
- The BBC’s Scotland editor Sarah Smith on the message being sent to Downing Street
- Follow BBC Scotland politics reporter Philip Sim who is at the conference
Ms Sturgeon told delegates that Scotland had the right to seek something better if there were prospects of an unstable future as part of the UK.
She said: “I am determined that Scotland will have the ability to reconsider the question of independence and to do so before the UK leaves the EU – if that is necessary to protect our country’s interests.
“So, I can confirm today that the Independence Referendum Bill will be published for consultation next week.”
On 24 June, the day after the UK voted to leave the EU, Ms Sturgeon said asecond independence referendum was “highly likely”.
Those who voted in Scotland backed remaining in Europe by 62% to 38% while the UK as a whole backed leave, by a margin of 52% to 48%.
As eye-catching announcements to open a conference go, Nicola Sturgeon’s about independence legislation is hard to top.
But there are still a lot of hurdles to clear before Scotland could potentially go back to the polls.
SNP brass are clear that this is still draft legislation – calling attention to the “distinction” between the consultation due to start next week and MSPs actually voting on a bill.
There is some precedent for the legislative process ahead, in the Referendum Bill which triggered the 2014 contest. But that had the approval of Westminster, and it’s quite possible – probable even – that Indyref2 would need a similar green light.
That remains a long way down the road, if it happens at all; this move doesn’t change things enormously in the first instance, at least from a constitutional standpoint.
What it has done is turbo-charge the delegates at the SNP conference. Ms Sturgeon’s announcement was greeted with massive cheers and a standing ovation – in marked contrast to the polite applause which greeted the passages about the Brexit deal.
Independence is what they want, and it trumps everything – the details of any Brexit agreement included.
Ms Sturgeon’s opening address also saw her issue a warning that the right wing of the Tory party was seeking to “hijack” the EU referendum result.
She told the 3,000 delegates gathered that the Tories were using the result as a “licence for xenophobia”.
Ms Sturgeon insisted that the Prime Minister Theresa May needed to respect the 62% who voted to remain in the EU.
She also confirmed that SNP MPs would oppose Brexit legislation when it comes before the House of Commons in 2017.
The MSP said: “I can confirm today that SNP MPs will vote against the Brexit Bill when it comes before the House of Commons next year.
“That bill will repeal the legislation that enacted our EU membership. Scotland didn’t vote for that and so neither will our MPs.
“But we will also work to persuade others – Labour, Liberals and moderate Tories – to join us in a coalition against a hard Brexit: not just for Scotland, but for the whole UK.
“The Conservative Party manifesto, on which Theresa May and all other Tory MPs were elected said this: ‘We are clear about what we want from Europe. We say: yes to the Single Market’.
“The prime minister may have a mandate to take England and Wales out of the EU but she has no mandate whatsoever to remove any part of the UK from the single market.”
At the beginning of the three-day conference, if was announced that SNP MP Angus Robertson had been voted the new deputy of the party.
Mr Robertson defeated Edinburgh East MP Tommy Sheppard, Alyn Smith MEP and Inverclyde councillor Chris McEleny to take 52.5% of the votes cast.
About 120,000 SNP members were entitled to vote in the contest.