The UK government has been found in contempt of Parliament for the first time ever.

Members of Parliament on Tuesday afternoon voted to find Theresa May's government in contempt of parliament after it refused to release official legal advice on the prime minister's Brexit deal.

The advice, given to Cabinet ministers last month, spells out the legal implications of the UK's draft Brexit deal with the European Union, including the controversial backstop for avoiding a hard Irish border.

The vote spells serious trouble for May as she prepares for an upcoming parliamentary vote on the deal.

LONDON — Theresa May's government has been found in contempt of Parliament after it refused to comply with a motion passed by Members of Parliament (MPs) demanding that it release the full legal advice on the prime minister's Brexit deal.

MPs voted 311 to 293 to find May's government in contempt on Tuesday afternoon. It is the first time in parliamentary history a UK government has been found in contempt by MPs.

Following the vote, the government announced that they will now comply with the demand to publish the advice in full, but only after a separate parliamentary committee has examined it.

"We have tested the opinion of the House twice on this very serious subject," the Leader of the Commons Andrea Leadsom said immediately after the historic vote.

"We have listened carefully and in light of the expressed will of the House, we will publish the final and full advice provided by the attorney general to Cabinet. But recognizing the very serious constitutional issues this raises, I've referred the matter to the privileges committee to consider the implications of the humble address."

The advice, that has already been given to ministers in May's Cabinet, spells out the legal implications of the UK's Brexit deal with the European Union, agreed on by negotiators last month.

It contains details on the most controversial aspects of the Withdrawal Agreement, including the backstop policy for avoiding a hard border on the island of Ireland after Brexit.

Attorney General Geoffrey Cox had said it was not in the public interest to publish the advice.

Attorney General Cox reacts to the vote:

Geoffrey Cox. BBC News

The motion, passed on Tuesday evening, did not name any individual minister.

However, if May's government had continued to refuse to comply with the demands to release the legal advice in full, then Attorney General Geoffrey Cox or other ministers could have faced suspension from Parliament.

Sir Keir Starmer, the shadow Brexit secretary, described the vote as a "badge of shame" for the government.

"Never before has the House of Commons found ministers in contempt of Parliament," the Labour MP said.

"It is highly regrettable that the government has let it come to this, but ministers left the opposition with no option but to bring forward these proceedings.

"By treating Parliament with contempt, the government has proved it has lost its majority and the respect of the House. The prime minister can’t keep pushing Parliament away or avoiding responsible scrutiny."

It is a long-standing constitutional convention in the UK that Parliament is sovereign, and the government must be subject to its will. However, May's government had argued that a separate convention against revealing confidential legal advice supplied to ministers had precedence.

MPs today rejected that position, as well as a separate motion to have the matter decided by a committee of MPs at a later date. The latter amendment was narrowly rejected by 311 votes to 307.

The decision, backed by a number of Conservative MPs as well as the Democratic Unionist Party, which has propped up her government, spells trouble for May's government as it approaches the crucial vote on the prime minister's Brexit deal due to take place next Tuesday.