Members voted by 309 to 242 in support of measures in the EU Withdrawal Bill
The British House of Lords have dealt a 10th defeat to the UK government on flagship Brexit legislation after ministers there were warned they are "playing with fire" in Northern Ireland.
Peers voted by 309 to 242, majority 67, in support of an amendment to the EU Withdrawal Bill.
The amendment requires the British government to act in a way compatible with the Good Friday Agreement, and to implement Brexit in a way that does not lead to a hard border between the Republic and Northern Ireland.
It is the 10th reverse on the EU Withdrawal Bill in the upper house, although ministers there have signalled their intent to overturn changes to the legislation when it returns to the House of Commons.
Theresa May's government have warned amended legislation could hamper Brexit negotiations with the EU.
Responding to the defeat, Jenny Chapman, Labour's Brexit minister, said: "This vote sends a clear signal to the Government that they must urgently find a solution to the Northern Ireland border.
"Ill-conceived compromises and unrealistic technological solutions are simply not good enough.
"The government's failure to act is holding back the Brexit negotiations and creating deep uncertainty for communities in Northern Ireland.
"Ministers should back this amendment and accept Labour's call for a new comprehensive customs union with the EU."
Richard Newby, the Liberal Democrat leader in the House of Lords, said: "This vote has recognised what Theresa May hasn't, that the issue of the Northern Ireland border is of paramount importance.
"We cannot risk Conservative incompetence and Brexit dogma creating a hard border, and we will not allow years of strong relations within these islands to be jeopardised by Brexit."
And Peter Hain, a former Northern Ireland secretary, said: "The government's half-baked plans on future customs arrangements risk rolling back years of progress on the island of Ireland, and threaten the re-emergence of a hard border.
"No parliament in its right mind should let that happen. Tonight's amendment, if also passed in the Commons, would be a step in the right direction.
"But on its own it would not be enough to avoid a hard border - that will ultimately depend on whether the government change course and negotiate to stay in the single market and customs union."
Among 19 Tory rebels who helped defeat the government on the amendment were ex-deputy prime minister Lord Heseltine and former ministers Lord Willetts, Viscount Hailsham and Baroness Altmann.
Chris Patten, a former EU commissioner, said: "I'll tell you what I think playing with fire is.
"I think playing with fire is blundering into the politics of Northern Ireland with a policy that is sometimes clueless, and sometimes delinquent, with a can of petrol and a box of matches in the other hand.
"I think that's playing with fire. I think that's what we're really in danger of doing."
The House of Lords will continue their scrutiny of the EU Withdrawal Bill into next week.