UK Prime Minister Theresa May had a rough day in Parliament on Tuesday, suffering a series of defeats that tested her government and the strength of her Brexit deal.

By day’s end, Parliament had voted to hold May’s government in contempt, and to give itself control over the future of Brexit. It was a big victory for pro-European members of Parliament, who dislike May’s deal but want to avoid a “cliff edge” scenario where the UK and the EU split up without any agreement or transition in place.

It also couldn’t come at a worse time for May, who is trying to sell her Brexit deal to Parliament before a vote that’s scheduled for Tuesday, December 11. The prime minister is facing an uphill battle, since her agreement is deeply unpopular. The pro-Brexit crowd says it fails to deliver on a decisive split with the EU, while the pro-European camp prefers to remain part of the EU, but at the very least wants stronger ties than the deal offers.

Tuesday’s contempt vote against her government — which is basically Parliament telling the government that it’s preventing the body from doing its job — had never happened before in British history.

The contempt vote was an embarrassment to May. But another vote dealt an even bigger blow: Parliament voted to give itself the power to decide on a “plan B” if May’s Brexit deal is defeated next week, which it looks like it’s going to be.

This will help change the course of Brexit, and defend against the possibility of a no-deal Brexit. It may also increase the possibility of a second referendum, or a “people’s vote” that would let the public weigh in. Events are still unfolding, but a couple of things seem clear: Britain remains bitterly divided over Brexit, and Parliament’s vote has transformed the stakes ahead of the vote on May’s deal next week.

Parliament holds the government in contempt over legal advice

May’s first defeat on Tuesday came after MPs voted to hold the government in contempt for failing to release full legal guidance on the Brexit deal, or an assessment on how the withdrawal agreement will affect the UK.

Attorney General Geoffrey Cox had delivered an overview of the legal advice to Parliament on Monday, but the government resisted releasing the full set of documents.

MPs accused the government of trying to hide something. Cox countered by saying that these documents are not traditionally released and he’d answer questions openly. “There is nothing to see here,” he said, according to the BBC.

There was some disagreement, and MPs voted 311-293 to force the government to release it. The Democratic Unionist Party (DUP), a Northern Ireland party who’s partnership with the Conservatives keeps May in power, bucked their alliance and voted with the opposition. (May’s government also lost a second vote, when ministers sought a delay by referring the issue to another committee.)

The government finally conceded and released the advice in full on Wednesday. Though the issue was a relatively narrow one, experts tell me, the action spoke to the bigger problems in the relationship between Parliament and May’s government.

The actual legal advice, however, was somewhat anti-climactic. It echoed much of what Cox had already told Parliament, though it still intensified the debate in Parliament on Wednesday.

The big issue here is the “Irish backstop” in May’s Brexit deal. The “backstop” guarantees that the border between Northern Ireland (part of the UK) and the Republic of Ireland (part of the EU) remains open even if the UK and EU can’t come to terms on a post-Brexit relationship.

The deal accomplishes this by creating an arrangement whereby the UK remains part of the EU customs union. The UK can’t unilaterally pull out of this set-up, which pro-Brexiters see as potentially trapping the UK in a relationship with the EU indefinitely. The legal guidance confirms Brexiteers’ worst fears, by warning that the UK could end up stuck in “protracted and repeated rounds of negotiations” for years.

The even bigger news: Parliament gets a stab at a Brexit “plan B”

The historic contempt vote revealed the cracks within May’s government. But another vote was far more consequential: Parliament approved an amendment to May’s deal that will give them a say in what happens next if May’s Brexit deal is defeated next week. And right now, that seems close to assured.

This vote, too, was an embarrassment for May because members of her own Conservative Party led the revolt, including her former allies. A total of 26 Conservative MPs joined the opposition Labour Party to approve the amendment, which ultimately passed 321 to 299.

But these were not the pro-Brexit hardliners that have been agitating against May of late. These rebels hailed mostly from the pro-Remain camp of her party, who see the wishy-washy Brexit deal as leaving the UK as worse off than it is now.

The amendment’s purpose is to allow Parliament to avert a no-deal Brexit if May’s deal goes down. But since much of the support came from the pro-European MPs, some see as increasing the possibility of a second referendum, or an official “people’s vote” on Brexit.

Supporters of a second referendum got another gift on Tuesday, when an advocate general on the European Court of Justice issued a nonbinding opinion that the UK can unilaterally decide to undo Brexit, without EU member states weighing in.

This wasn’t an official ruling, but it was nonetheless a win for the pro-Remainers.

A second referendum remains a tricky endeavor, as it would need to happen before the Brexit deadline of March 29, 2019, or require the EU to offer an extension. It’s also not clear what the second referendum would ask: a do-over of the 2016 leave or remain referendum? Putting May’s deal to a people’s vote? Or some combination of all three?

Support for Brexit among Britons has declined, especially as it’s become clearer that breaking up is messier than advertised and potentially far more damaging to the economy. But there’s no guarantee Britain is ready to change its mind completely on Brexit, and a good chunk of the population that supports exiting the EU will be doubly angry if it does: First, because Brexit won’t happen, and second, because it effectively makes null and void the 2016 “leave” victory.

To be clear, there’s no guarantee that a second referendum will happen. Parliament could use this new power to try to force May to go back to the EU and renegotiate, though EU leaders have already said it’s this deal or no deal. Or they could opt to push for an even softer Brexit, something that would keep the UK even more closely aligned in the customs union and single market — a setup countries such as Norway have.

There are a lot of different possible outcomes, and therein lies the rub. Just because Parliament now has say over a “plan B” doesn’t mean Parliament knows what it actually wants to do if May’s deal does fail. It remains split, and though some Tories and the opposition united to pass this amendment, that alliance is shaky at best.

“Parliament is giving itself this power and that will be very influential,” Simon Usherwood, a professor at the University of Surrey and deputy director of an independent Brexit think tank, told me. “But it’s not clear at this point what it can use this power for.”

And there’s one more complication. This might not be all bad news for May. The pro-Europe members of Parliament won a victory, which means the odds of a “hard” or no-deal Brexit just decreased.

That puts the pressure on hardline Brexiteers: If they want a Brexit, the best vehicle might be to go ahead and support the Brexit deal they despise — or risk a second referendum or an even closer relationship with the EU in the future.

This might not be enough to push May’s agreement over the edge. But it now looks like Parliament, not May, may soon have the power to decide Brexit.