A motion warning the legislation “would undermine the rule of law and damage the reputation of the United Kingdom” was passed by 395 votes to 169 – a majority of 226.
A total of 39 Conservative peers rebelled against Boris Johnson, including Lord Keen of Elie, the former advocate general for Scotland, who resigned over the Internal Market Bill last month.
Lord Judge, a former lord chief justice, who proposed the regret amendment, said: "The fact of the matter is the law would be broken.
“There can be no getting away from it. You don't have to be a lawyer to understand the reputational damage to the United Kingdom.
“We cannot resile from the fact that we are breaking the law if this bill is enacted.”
The Constitution Unit, a research centre, said the defeat was the biggest government defeat in the House of Lords since reform in 1999.
The defeat, on a ‘regret’ motion, is essentially symbolic and does not, by itself, overturn any of the provisions in the legislation.
However, it signals to the government that there is almost no chance of it getting through its remaining stages in the Lords without significant changes.
The legislation provoked uproar in the EU and the USA, by paving the way to override the withdrawal agreement on the use of state aid and the customs checks required on goods crossing the Irish Sea.
The prime minister was accused of bringing a no-deal Brexit significantly closer and of undermining the still-fragile peace in Northern Ireland.
Watch: Boris Johnson tells the UK to prepare for no-deal Brexit
Downing Street has argued the measures are a fallback option, should the trade talks fail, and insisted it remains committed to the withdrawal deal, an international treaty.
It was able to deflect a major Conservative revolt in the Commons after agreeing that MPs must give approval before the powers in the bill can be enacted.
Justin Welby, the Archbishop of Canterbury, former Commons speaker Baroness Boothroyd and ex-Tory leader Lord Howard of Lympne were among the bill’s critics in the upper house.
Lord True, the Cabinet Office minister opened with a dig at the group of archbishops which attacked the legislation at the weekend.
“I did have some reflections during the course of the debate and, at one point, found myself asking if Henry VIII's foundation of the Church of England was fully in accord both with our domestic law and international obligations,” he said.
But he insisted: “We share a full and fundamental respect for and belief in the rule of law.”
And, defending the “limited, contingent proposals" in the bill, he said the government “does not accept that these safeguard provisions render our country, as has been claimed, an international pariah”.
Watch: What are Freeports?