LONDON - As the gray dawn came up over London on the morning of June 9, 2017, Theresa May had one urgent mission: to stop Jeremy Corbyn from becoming prime minister.

May was hunkered down inside her Conservative Party’s headquarters with her closest aides, trying to make sense of the shocking failure of her campaign to win a snap general election. By 4:30 a.m. it was clear she’d lost her majority, and the socialist Labour Party leader was within striking distance of replacing her in government.

May held on — just — and has battled for 23 months at the head of a minority government. But the core policy she’s been fighting to implement — an orderly divorce from the European Union — now rests in the hands of the man she fought to keep from power.

Desperate for Labour votes to help her Brexit deal pass in the House of Commons, May set out to woo Corbyn in April, giving the opposition leader the chance to dictate the terms of the U.K.’s withdrawal from the bloc.

Based on accounts from people familiar with both sides of the negotiations, the political courtship has been uncomfortable and uneasy. It’s set to reach crunch point in a meeting on Tuesday and the outcome could be momentous for the fate of Brexit.

If the talks fail, the chances of another referendum or even an emergency election will rise, while May herself could be forced out and ultimately replaced with a Brexit hardliner who is happy to leave the EU without any deal at all.

In recent days officials on both sides have privately sounded optimistic about the prospects of an agreement. In part, that’s because of the generally positive atmosphere in which at least some of the discussions have taken place.

Critically for the Tory side, Seumas Milne, Corbyn’s chief strategist, is said to be fully engaged and serious in the meetings that have taken place, asking detailed questions about the government’s position and the offers on the table, in a sign he’s interested in doing a deal.

The discussions on how to ensure workers’ rights remain protected after Brexit have gone well. Business Secretary Greg Clark and his shadow, Rebecca Long-Bailey, produced successful results which are likely to be taken forward even if no wider deal is possible.

Likewise, pro-Brexit Environment Secretary Michael Gove has sat down for constructive talks with his Labour counterpart, Sue Hayman, on securing ongoing standards of environmental protections. May’s aides have even gone as far as drafting a media plan for how to handle the publicity around the announcement, in preparation for an agreement being signed.

Yet the tensions pulling the two sides apart are arguably stronger than the temptation to do a deal. Some pro-Brexit Cabinet ministers, including Brexit Secretary Steve Barclay, are deeply skeptical of the whole process. He seems far less engaged in the meetings than others, according to people familiar with the situation.

There remains an abiding wariness and suspicion on both sides. Government officials have written down May’s offers and handed them out on pieces of paper to the Labour team to read in the meetings. At the end of those meetings, the government side collects those papers back again to stop Corbyn’s team taking them away and leaking the details.

On Sunday, May appealed to Corbyn to “do a deal” but Labour’s finance spokesman, John McDonnell, declared he did not trust her after details of her offer were leaked to the press.

The two party leaders have met twice in person and are not expected to meet again unless a deal is ready to be signed.

The major focus of the talks is on future customs arrangements between Britain and the EU. May is under pressure to compromise and abandon her promise to keep the U.K. out of a formal customs union with the bloc. She’s willing to give ground on this issue but it’s not yet clear whether the offer she has in mind will go far enough to win over Corbyn.

A temporary customs arrangement, alongside alignment with EU market regulations, would give certainty over the future until the next general election scheduled for 2022. Whoever wins that vote will be able to pursue softer or harder forms of Brexit.

According to one of May’s most senior colleagues, the goal for the talks is to reach compromise positions on both the longer term U.K.-EU customs regime and the prospects of a second referendum that both Labour and the Tories can live with.

There is some sympathy for Corbyn at the very top of May’s team. One of her most senior aides acknowledged that he has an extremely difficult calculation to make on a second referendum. Many Labour politicians want a so-called people’s vote on the terms of any Brexit deal but Labour is reluctant to promise one, in part over fears that this will alienate pro-Leave voters in the party’s northern English heartlands.

If the talks break down, the focus will switch to whether Labour and the government can agree on a way to put alternative options to a series of so-called indicative votes in Parliament, allowing rank-and-file politicians to choose the way forward. Previous attempts to find a majority in Parliament have failed.

Even if both leaders can agree to a blueprint for the divorce, questions will remain over how many members of their own parties will support it.

Tory member of Parliament Lee Rowley’s message to May about the negotiations with Corbyn was succinct. “Stop this madness,” he wrote on Twitter, saying his views are supported by voters. “People didn’t vote for you to do a deal with a Marxist.”