Theresa May's Brexit backstop plan risks a "stalemate" and "protracted rounds of negotiations" with the EU, the full legal advice on her deal says.

Newly published documents show the PM was told an arrangement designed to prevent a hard Irish border could last "indefinitely" and the UK could not "lawfully exit" without EU agreement.

The Democratic Unionists said this would be "devastating" for the UK.

But Mrs May rejected SNP claims she has misled Parliament on the issue.

Ministers were forced to publish Attorney General Geoffrey Cox's full advice after ministers were found to be in contempt of Parliament on Tuesday for providing only a legal overview earlier this week.

Speaking in the Commons, the prime minister said there was "no difference" between the two documents and the legal position on her proposed "temporary" customs arrangement with the EU was clear.

While the UK would have no unilateral right to withdraw from the backstop - a measure designed to prevent the return of physical checks on the Irish border by the UK and EU sharing a single customs territory - she insisted neither the UK nor the EU wanted it to come into force in the first place.

But the Democratic Unionists said the advice was explicit that Northern Ireland would end up subject to different EU regulatory and customs rules from the rest of the UK and be treated as a "third country" in terms of trade with England, Scotland and Wales.

The BBC's political editor Laura Kuenssberg said that, amid fears Mrs May was heading for a heavy defeat in next Tuesday's vote on the final deal, there was talk among MPs about a compromise amendment being tabled on the backstop, giving Parliament some kind of check on it coming into force.

What does the full advice to PM say?

The government argued that Mr Cox's analysis of the Brexit deal, published on Monday, was adequate and disclosing his full and final advice would be against the national interest.

Labour and other opposition parties said ministers had "wilfully" refused to comply with a binding vote in the Commons last month which demanded full disclosure and MPs agreed with this in a vote on Tuesday.

In his six-page letter to Mrs May, written on 13 November but published on Wednesday, Mr Cox said the "current drafting" of the backstop "does not allow for a mechanism that is likely to enable the UK to lawfully exit the UK wide customs union without a subsequent agreement".

"This remains the case even if the parties are negotiating many years later and even if the parties agree that talks have clearly broken down and there is no prospect of a future relationship agreement."

The backstop has become a defining issue for many Tory critics of the PM's deal - who say that it infringes the UK's sovereignty and will prevent the UK from being able to negotiate its own trade deals.

Mr Cox said that despite assurances that the arrangement was not intended to be permanent "in international law the protocol would endure indefinitely until a superseding agreement took its place".

"In the absence of a right of termination, there is a legal risk that the UK might become subject to protracted and repeated rounds of negotiations," he said. "The resolution of such a stalemate would have to be political."

However, he also put forward the case that the "risk" of getting entangled in the backstop had to be weighed "against the political and economic imperative of both sides to reach an agreement that constitutes a politically stable and permanent basis for their future relationship".

Analysis: In black and white

The BBC's legal correspondent Clive Coleman

When lawyers give legal advice they are expected to speak frankly.

Many will conclude this advice is franker and starker than the way in which the government has presented the legal implications of the withdrawal agreement.

In particular on the Northern Ireland backstop, it is there in black and white, that in the absence of an agreement replacing it, the backstop will continue indefinitely. The UK could not force the EU to conclude an agreement bringing it to an end.

That punctures the government's optimism on the issue. Whereas Article 50 allowed the UK to pull out of the EU, there is no provision for the UK to pull out of the withdrawal agreement. That will pour petrol on the flames of the political debate.

May defends advice at Prime Minister's Questions

The prime minister has insisted there can be no Brexit deal without a backstop of some kind to protect commitments made to Northern Ireland in the Good Friday Agreement.

But she came under fire at Prime Minister's Questions from the SNP's Westminster leader Ian Blackford.

"The legal advice is clear," he said. "It states: despite statements in the protocol it is not permanent, in international law the protocol would endure indefinitely. Since the prime minister returned from Brussels with her deal, the prime minister has been misleading the House inadvertently or otherwise.

"Is it time that the prime minister took responsibility for concealing the facts on her Brexit deal from members in this House and the public?

The PM told MPs all the material published in the past few days was consistent.

But the DUP's Sammy Wilson said other EU members would use the backstop as a "cudgel" to obtain concessions from the UK in future trade talks.

And former foreign secretary Boris Johnson suggested the backstop could easily be dispensed with as it was "not essential" to the wider deal and everybody believed "you can solve this without a hard border".

"Let's just get rid of this nightmarish system that keeps us effectively clamped in the EU, and really stopping Brexit from taking place," he told the BBC's Laura Kuenssberg.

Labour said the legal advice showed the "central weakness" of the PM's Brexit deal while the Lib Dems said it would leave the UK trapped in a "Brexit hamster wheel".

Debate on Brexit deal continues

Media playback is unsupported on your device

Media captionSam Gyimah: Brexit negotiations have been set up for failure

The second of five days of debate on Mrs May's Brexit agreement is under way, focusing on security and immigration.

The government suffered three embarrassing defeats on Tuesday, on the role that MPs will play if Mrs May's deal is rejected as well as the disclosure of the legal advice.

Ex-defence secretary Sir Michael Fallon told MPs he could not support Mrs May's deal, saying it was too much of a "gamble" to sign up to EU rules when the UK did not know what it was getting in return.

"We put all our cards and all our money on the table and we wait for another two years for the EU to set the rules of the game. That is a risk too far".

But Chancellor Philip Hammond warned that if the deal was rejected, either the UK could end up leaving without a deal or Brexit could unravel entirely, leaving "half the nation feeling betrayed".

"I take the judgement that when there is a deal on the table that has very, very modest costs to the economy, which will allow us to move on as a nation both economically and politically, I judge that even narrowly, economically that will be in the best interests of the country," he told the Treasury committee.

Earlier, International Trade Secretary Liam Fox warned there was a risk of Parliament trying to "steal Brexit from the British people".

He said there was a "natural Remain majority" in Parliament and that any attempts to delay the UK's departure or overturn the 2016 referendum result would be a "democratic affront".