Media playback is unsupported on your device Media caption The moment the voting figures were announced and the government was told to disclose its legal advice over Brexit.

Theresa May has suffered three Brexit defeats in the Commons as she set out to sell her EU deal to sceptical MPs.

Ministers have agreed to publish the government's full legal advice on the deal after MPs found them in contempt of Parliament for issuing a summary.

And MPs backed calls for the Commons to have a direct say in what happens if the PM's deal is rejected next Tuesday.

Mrs May said MPs had a duty to deliver on the 2016 Brexit vote and the deal on offer was an "honourable compromise".

She was addressing the Commons at the start of a five-day debate on her proposed agreement on the terms of the UK's withdrawal and future relations with the EU.

The agreement has been endorsed by EU leaders but must also be backed by the UK Parliament if it is to come into force. MPs will decide whether to reject or accept it on Tuesday 11 December.

Mrs May said Brexit divisions had become "corrosive" to UK politics and the public believed the issue had "gone on long enough" and must be resolved.

In other Brexit-related developments:

Analysis: A terrible day for May but...

Image copyright PA

The BBC's political editor Laura Kuenssberg

The prime minister has had a terrible day today as the government made history in two excruciating ways.

Ministers were found to be in contempt of Parliament - a very serious telling off - and the government had a hat trick of defeats - the first time since the 1970s that's happened.

As you'd expect too, MP after MP after MP rose after Theresa May's remarks to slam her deal as Tory divisions were played out on the green benches, with harsh words exchanged.

But in this topsy-turvy world, the overall outcome of the day for Mrs May's big test a week tonight might have been not all bad...

What was the legal advice row?

Image copyright PA Image caption The attorney general said his full advice to ministers should remain confidential

By 311 votes to 293, the Commons supported a motion demanding full disclosure of the legal advice given to cabinet before the Brexit deal was agreed.

The move was backed by six opposition parties, including Northern Ireland's Democratic Unionist Party which has a parliamentary pact with the Conservatives.

It came after Attorney General Geoffrey Cox published a summary of the advice on Monday and answered MPs questions for three hours - but argued that full publication would not be in the national interest.

Labour had accused ministers of "wilfully refusing to comply" with a binding Commons vote last month demanding they provided the attorney general's full and final advice.

After Labour demanded the advice should be released ahead of next Tuesday's key vote on Mrs May's deal, Commons Speaker John Bercow said it was "unimaginable" this would not happen.

In response, Commons Leader Andrea Leadsom said she would "respond" on Wednesday, but would ask the Commons Privileges Committee to consider the constitutional repercussions.

Media playback is unsupported on your device Media caption BBC political correspondent Leila Nathoo explains how things unfolded

An attempt by ministers to refer the whole issue, including the government's conduct, to the committee of MPs was earlier defeated by four votes.

The privileges committee will now decide which ministers should be held accountable and what sanction to apply, with options ranging from a reprimand to the more unlikely scenario of a minister being suspended from the Commons.

Lib Dem leader Sir Vince Cable said the result left the government "on the ropes", adding: "Theresa May's majority has evaporated, and the credibility of her deal is evaporating with it."

MPs seek to influence Brexit process

The prime minister suffered a further setback on Tuesday as MPs backed, by 321 votes to 299, changes to the parliamentary process should the Commons vote down her deal next week.

If that happens, the government has 21 days in which to return to the House and set out what it plans to do next.

But Tory Dominic Grieve's motion means that instead of MPs being confined to merely taking note of what the government tells them, the Commons would be able to exert more influence by voting on what they wanted the government to do as well.

Tuesday's vote, in which 26 Tory MPs rebelled, could potentially tilt the balance of power between government and Parliament if, as expected, MPs push for a "Plan B" alternative to Mrs May's deal and also seek to prevent any chance of a no-deal exit.

Mr Grieve, who has expressed support for another Brexit referendum, told Channel 4 News he was not seeking to "guarantee a particular outcome" if Mrs May's deal went down.

But he said it would "allow the UK time to consider its options", including potentially re-starting negotiations with the EU or giving the public the final say.

What did the PM say?

Media playback is unsupported on your device Media caption Theresa May: "Worth taking a moment to reflect on how we got here."

As she sought the backing of the Commons for her Brexit deal, the prime minister said she was confident the UK would enjoy a "better future" outside the European Union.

She said the "honourable compromise" on offer was "not the one-way street" many had portrayed it to be and that the EU had made it clear that the agreement would not be improved on.

"I never said this deal was perfect, it was never going to be. That is the nature of a negotiation," she said.

"We should not let the search for a perfect Brexit prevent a good Brexit... I promise you today that this is the very best deal for the British people and I ask you to back it in the best interest of our constituents and our country."

And what about her critics?

But Labour leader Jeremy Corbyn said it was a bad deal for the UK and Labour would seek a vote of no confidence in Mrs May if she could not get it through Parliament.

"This House will make its decision next Tuesday," he said. "I hope and expect this House will reject that deal.

"At that point, the government has lost the confidence of the House. Either they have to get a better deal from the EU or give way to those who will."

Media playback is unsupported on your device Media caption Not everyone agreed with Boris Johnson's analysis of the Brexit deal...

Nigel Dodds, the leader of the DUP in Westminster, said the agreement "falls short" of delivering Brexit "as one United Kingdom" and would mean entering "a twilight world where the EU is given unprecedented powers over the UK".

"We would have to rely on the goodwill of others to ever leave this arrangement," he said.

"So... the UK's future as a strong and independent global trading nation standing together is in real and imminent jeopardy - an outcome that doesn't honour the referendum or take back control of our laws, our money and our borders."

Ex-Foreign Secretary Boris Johnson dismissed the deal as a "paint and plaster pseudo-Brexit" and said its supporters would be "turning their backs" on the 17.4 million Leave voters.

"If we try to cheat them now, as I fear we are, they will spot it and will never forgive us," he said.

'Moment of self-harm'

The leader of the SNP in Westminster, Ian Blackford, said beneath the "theatre" of the past few months was the "cold, hard truth" that this deal was "a moment of self-harm in our history".

He said it was "difficult" and "a real sorrow" to even respond to a motion that could see the UK leave the EU - an institution that he called the "greatest peace project in our lifetime".

"It is not too late to turn back. Fundamentally, there is no option that is going to be better for our economy, jobs, and for our communities than staying in the European Union.

"And it is the height of irresponsibility of any government to bring forward a proposition that is going to make its people poorer."

However, in closing the debate shortly after 01:00 GMT on Wednesday, Brexit Secretary Stephen Barclay argued the deal would bring "real changes which will improve the livelihoods of people up and down the country".

"This deal is a choice between the certainty of continued co-operation or the potentially damaging fracture of no deal, or indeed the instability of a second referendum vote," he said.

"Rejecting this deal would create even more uncertainty at a time when we owe it to our constituents to show clarity and conviction."