Image copyright PA Image caption Nicola Sturgeon has accused a Westminster "faction" of trying to "rein in "Scotland

Nicola Sturgeon has accused the UK government of using Brexit to undermine devolution.

In a speech in Edinburgh, the first minister said the Scottish Parliament faced a "graver challenge" after "20 years of progress".

She also warned that without compromise, a second independence referendum may become a "necessary" way of protecting Scotland's interests.

The UK government said Ms Sturgeon had completely misrepresented its position.

In her address to the David Hume Institute, Ms Sturgeon argued that Scotland voting to remain in the EU while the UK as a whole voted to leave had re-opened the "democratic deficit" which fuelled demand for a Scottish Parliament in the 1980s and 1990s.

Image copyright Getty Images Image caption The Leave campaign promised to return powers over areas such as fishing and agriculture to Holyrood after Brexit

The first minister claimed recent statements by the UK government suggested elements of farming and fishing policy could be taken back to Westminster after Brexit, despite promises by the Leave campaign that they would be handed to Holyrood.

She told her audience in Edinburgh: "After 20 years of progress, devolution in Scotland is perhaps facing a graver challenge from the current Westminster government.

"The democratic deficit that fuelled the demand for the Scottish Parliament in the 80s and 90s has opened up again."

Ms Sturgeon insisted on her right to call a second referendum on Scottish independence should the UK government fail to offer a compromise ahead of the triggering of Article 50.

She went on: "If it doesn't it will show that the democratic deficit which people voted to end in 1997 doesn't just endure, it continues to have the potential to cause harm to our interests, to our international relationships, to our very sense of our own identity.

"So if the circumstances arise proposing a further decision on independence, it wouldn't simply be legitimate, it would arguably be a necessary way of giving the people of Scotland a say in our own future direction.

"It would offer Scotland a proper choice on whether or not to be part of a post-Brexit UK, a UK that is undoubtedly on a different path today than that envisaged in 2014.

"And in the absence of compromise from the UK government, it may well offer the only way in which our voice can be heard, our interests protected and our values upheld."

Did Nicola Sturgeon change her speech?

Analysis by BBC Scotland political correspondent Glenn Campbell

It was the line that was left unspoken.

In advance of her Brexit speech, Nicola Sturgeon's team issued an extract from the text.

They advised that the first minister would warn of a Conservative "attack on the very foundations" of devolution.

But when it came to it, the first minister did not utter that key phrase.

The Conservatives have now written to her to explain what they suspect was a "retraction".

But Ms Sturgeon told the BBC that she did not leave out the phrase deliberately.

It's thought the first minister used her prepared text as a guide and cut sections to keep to time.

She has also made clear that she does think UK ministers may be preparing a "power grab".

While David Mundell, the Scottish secretary said during Scottish Questions in the Commons on Wednesday that further devolution is "guaranteed".

Ms Sturgeon notes that the UK government does not specify what powers will come to Holyrood.

She suspects that full control of fishing and farming will not be transferred from Brussels to Edinburgh when the UK leaves the EU.

Responding to Ms Sturgeon's speech, a UK government spokesman said: "These claims completely misrepresent the UK government's position.

"We have been very clear that no decisions currently taken by Holyrood will be taken away.

"We have also said that we will use the opportunity of bringing decision-making back to the UK to ensure that more decisions are devolved.

"As a result of the Scotland Act passed last year, Holyrood is becoming one of the most powerful devolved parliaments in the world.

"The only threat to devolution is the policy of taking Scotland out of the United Kingdom."

'Ridiculous scaremongering'

Scottish Conservative leader Ruth Davidson said the "hyperbole from the first minister takes synthetic grievance to a whole new level", adding: "Frankly, she sounds shrill".

Ms Davidson said: "Nicola Sturgeon's attempt to use Brexit to manufacture the case for a second referendum has quite simply failed.

"She should now take it off the table so Scotland and the UK can work to get the best Brexit deal possible."

Scottish Labour leader Kezia Dugdale accused Ms Sturgeon of "ridiculous scaremongering".

She said: "The Scottish Parliament has major new powers over tax and welfare, which the SNP simply refuses to use.

"While the Tories' reckless Brexit gamble will undoubtedly harm Scotland's economy, there is an opportunity to repatriate powers here from Brussels - including fishing and agriculture."