BRUSSELS — European and British negotiators struck a deal Thursday to split Britain from the European Union, raising the prospect that the country could be out of the bloc by the end of October.

Negotiators working through the night in Brussels agreed on a draft Thursday morning after Prime Minister Boris Johnson signed on despite lingering questions about the feuding factions in London. The agreement still needs approval by European leaders and the British Parliament.

“This deal represents a very good deal both for the E.U. and the U.K.,” Johnson said in Brussels ahead of the meeting. “Now is the moment for us to get Brexit done and then together to work on building our future partnership.”

British lawmakers passed a law requiring Johnson to ask to delay Brexit past the Oct. 31 deadline if a deal to ease the exit is not in place by Saturday.

“Where there is a will, there is a #deal - we have one! It’s a fair and balanced agreement for the EU and the UK and it is testament to our commitment to find solutions,” European Commission President Jean-Claude Juncker wrote on Twitter.

But even as European leaders appeared to embrace the hard-fought agreement, serious doubts remained about whether Johnson could rally Parliament behind him. Already, some hardcore Brexiteers are saying they will hold out against him, the Labour Party is opposed, and Northern Ireland’s Democratic Unionist Party is in rebellion.

The 10 members of that party have held outsize power over Brexit in Parliament. The Northern Ireland unionists, who are committed to serving their Protestant, pro-British, antiabortion and conservative base, were brought in to prop up the government of Johnson’s predecessor, Theresa May, after she lost her majority in the Parliament in 2017 elections. To support May's government, they extracted a promise that the government spend 1 billion pounds (about $1.3 billion) in Northern Ireland.

If there is a vote on the deal in Parliament on Saturday, Johnson will face a huge showdown. Since he became prime minister, Johnson’s working majority has vanished. From one seat up, he is now 43 seats down, meaning he will need the support of other parties to get the deal approved.

“It is our view that these arrangements would not be in Northern Ireland’s long-term interests,” the Democratic Unionist Party said in a statement. “Saturday’s vote in Parliament on the proposals will only be the start of a long process to get any withdrawal agreement bill through the House of Commons.”

Nor did other parties appear eager to lend Johnson a hand. Jeremy Corbyn, leader of the opposition Labour Party, said that from what was known, the agreement reached on Thursday was an “even worse deal” than May’s. He said that the “best way to get Brexit sorted is to give the people the final say in a public vote.”

Under the deal — which focuses mostly on the split from the European Union, not on how the two sides will work together in the future — Britain would leave the European Union but would continue to apply E.U. rules until the end of 2020 in a transition period that would soften the split. E.U. and British negotiators would try to hammer out a trade deal and other elements of their future relationship in the meantime. The transition period could be extended up to two years if both sides agree.

The split would be a harder break than ever envisaged by May, Johnson’s predecessor as prime minister, with Britain potentially taking a sharply different line on trade, taxes and regulations. May’s plans would have left Britain tightly integrated.

But Northern Ireland would remain largely aligned with the bloc, at least for now, even though it is leaving the E.U. along with the rest of the United Kingdom.

The trickiest part of the talks always centered on the border between Northern Ireland and the Republic of Ireland, which remains in the European Union. 

Borderless movement has been a key part of the Good Friday Agreement that ended decades of violence in the region, but it was challenged by Brexit.

Elements of the new deal crossed red lines that previous British leaders ruled out. British authorities will have to conduct customs checks in the Irish Sea for goods moving inside their own country, as Northern Ireland would remain locked into most E.U. regulations and trade rules.

But the E.U. also made significant concessions that it had previously said were impossible. After four years, Northern Ireland lawmakers would have a vote on whether they wanted to stay so closely aligned with the European Union. 

If they decline, that would likely require a hard border, something the E.U. had previously refused to countenance.

And Northern Ireland’s tax rules could be different enough from Europe’s that some leaders fear they could lead to smuggling and other attempts to exploit the situation.

Still, E.U. leaders sounded largely positive as their summit got underway.

“It’s really for everyone much better if we agree and we are able to come here with a positive message,” said Luxembourg Prime Minister Xavier Bettel.

Diplomats said before the announcement that it would be possible  — just barely — for a deal reached Thursday to be ratified by the European Parliament by the end of the month, giving Johnson a strong incentive to wrestle his warring political tribes into submission.

One senior E.U. official said Johnson told the Europeans that he could get a deal ratified in Britain in just six days. 

Diplomats now expect E.U. leaders to discuss the deal and potentially to give it a nonbinding green light later Thursday.

Then Johnson would likely seek approval from his Parliament on Saturday.

 If he succeeds, the European Parliament would need to ratify the agreement, after which E.U. leaders would finally sign on, this time in a binding manner.

“Discussions over the past days have at times been difficult. But we have delivered, and we have delivered together,” said E.U. chief Brexit negotiator Michel Barnier.

Johnson told Juncker that he “has faith in his ability to convince the majority he needs in the House of Commons,” Barnier said.

Booth reported from London. Karla Adam in London contributed to this report.