Brexit was finally passed into law Thursday with royal assent from Queen Elizabeth II — leaving the UK set to finally leave the Europen Union next week after almost four years of bitter debate.

Deputy Speaker Nigel Evans sparked cheers of “Hear! Hear!” in the House of Commons on Thursday afternoon when he announced that the Withdrawal Agreement Act had been signed off on by the Queen.

It was its last obstacle in the UK, with it now up to EU leaders to formally ratify the law in a vote next Wednesday for Britain to leave the bloc on schedule on Friday next week.

Prime Minister Boris Johnson — who staked his leadership on getting Brexit through — was understandably jubilant.

“At times, it felt like we would never cross the Brexit finish line, but we’ve done it,” he said Thursday.

It is not expected to face any obstacles when the bloc votes next week.

The EU Parliament’s constitutional affairs committee voted by a large margin Thursday to approve the Brexit withdrawal deal, preparing the way for a vote of all European lawmakers in Brussels next Wednesday.

“It’s a historical moment, albeit a somber moment, for us. We deeply regret this outcome,” committee chair Antonio Tajani said after the 23-3 vote.

It ends a yearslong battle to get Brexit approved — but still leaves deep divisions in the UK.

After the royal assent was announced, Scottish National Party lawmaker Ian Blackford said the UK was in a “constitutional crisis” because the legislatures in Scotland, Wales and Northern Ireland did not back the Brexit bill.

“Boris Johnson has trampled over the democratic votes in Edinburgh, Belfast and Cardiff,” Blackford fumed.

Once the EU Parliament ratifies Brexit, the UK and the EU will begin negotiating in February to work out their future ties.

The negotiations are expected to deliver new relationships for trade, security and other policy issues by the end of 2020.

The UK also plans to negotiate a trade deal with the US.

US Commerce Secretary Wilbur Ross, speaking Thursday at the World Economic Forum in Switzerland, sounded optimistic such a deal would get done.

“Both are very heavily services oriented and within services, such as financial services, there’s already a pretty high degree of integration and coordination, so it should be much easier mechanically,” he said.

With Post wires