LONDON — Britain’s divorce negotiations with the European Union hit a major snag on Monday, when a hard-line Northern Ireland party that is a crucial ally of Prime Minister Theresa May pulled its support at the last minute from an agreement on the future of the border between the United Kingdom and Ireland.

The abrupt decision, which appeared to take Mrs. May by surprise as she held talks in Brussels, derailed a draft deal between Britain and the European Union that is a prerequisite for moving on to the next stage of negotiations.

It denied Mrs. May a much-needed breakthrough in the stalled talks. It frustrated leaders of the European Union, who increasingly appear to have the upper hand in the discussions. And it underscored yet again Mrs. May’s weakness at home, and the complexity of the task facing her as Britain tries to unscramble more than four decades of European integration.

“Once again Theresa May has come out of Brexit talks with her tail between her legs,” said Tom Brake, a member of Parliament from the Liberal Democrats, an opposition party. “As each day goes by, it becomes clearer that the best deal for everyone is to stay in Europe. The people of the U.K. must be given a vote on the deal and an opportunity to exit from Brexit.”