It wants to change the Northern Ireland Protocol to make it easier for some goods to flow from Great Britain to Northern Ireland.
But the EU opposes the move, saying that going back on the deal breaches international law.
The government said there is "no other way" of safeguarding essential interests of the UK.
It argues the term "necessity" is used in international law to justify situations where "the only way a state can safeguard an essential interest" is by disapplying - or breaking - another international obligation.
It adds that action taken must not "seriously impair" essential interests of other states.
The alterations are set out in the Northern Ireland Protocol Bill, to be debated and voted on by Parliament.
The government is promising to remove "unnecessary" paperwork on goods checks and that businesses in Northern Ireland will get the same tax breaks as those elsewhere in the UK.
The bill will also ensure that any trade disputes are resolved by "independent arbitration" and not by the European Court of Justice, it adds.
Foreign Secretary Liz Truss said it was "a reasonable, practical solution to the problems facing Northern Ireland" and that the UK could "only make progress through negotiations if the EU are willing to change the protocol itself", adding: "At the moment they aren't."
"We are very clear that we're acting in line with the law," she said.
The government said it would prefer a "negotiated solution" with the EU that avoids the need for the bill to become law.
Three parties in Northern Ireland - Sinn Féin, Alliance and the SDLP - say the protocol is necessary to mitigate the effects of Brexit in Northern Ireland.
However no unionist supports the protocol as it stands.
The Democratic Unionist Party (DUP), which won the second-most seats in the recent Northern Ireland Assembly elections, argues it creates a divide that could lead to the break-up of the UK.
It is refusing to set up a new ruling Northern Ireland executive with Sinn Féin, which won most seats in the election, until changes are made to it.
Sinn Féin's Stormont leader Michelle O'Neill accused the prime minister of creating more instability and uncertainty in Northern Ireland.
"Boris Johnson's action is illegal, he is in clear breach of international law, regardless of the detail," she said.
"He himself signed up to an agreement, he signed on the dotted line and he's now legislating to breach that international agreement."
She added that the protocol was working - and she accused the DUP of blocking the formation of an Executive in Northern Ireland.
DUP leader Sir Jeffrey Donaldson said: "I don't believe what the government is proposing is illegal. I believe it is a solution and that is what we need - solutions."
He added: "We have strong support from across unionism for the stand that we are taking.
"I believe that our pressure is seeing progress being made and we will continue to work with government to ensure that this legislation progresses."
The government, in its legal justification for this new bill, has also cited Article 16 - a clause in the NI Protocol that allows either side to take safeguarding measures if applying the protocol leads to serious economic, societal or environmental difficulties that restrict trade.
The government has argued that maintaining peace in Northern Ireland, protecting the Good Friday Agreement, and preserving economic and social ties between Northern Ireland and Great Britain are "essential interests" of the UK.
But it says the protocol currently stands as a "barrier" to forming a new governing executive in Northern Ireland.
It says while the government's preference is a negotiated outcome with the EU, in the meantime the "strain" that the protocol is placing on Northern Ireland has reached the point where the government "has no other way of safeguarding the essential interests at stake" than this new bill.
There's no appetite amongst EU leaders for a full-blown trade war with the UK.
They have their hands full with the cost of living crisis and the war in Ukraine.
So the EU didn't want to overreact to today's UK government legislation proposal - after all it's not law yet - but neither did it want to underreact.
Attempting unilaterally to over-ride large parts of the protocol agreed and signed by Boris Johnson is seen as a very big deal in Brussels.
As a warning, the EU will look to re-start legal proceedings against the UK for alleged breaches of the protocol - such as failing to carry out certain checks.
At the same time, the EU's chief negotiator has implored the UK to come back to the negotiating table.
He says the EU will soon publish new proposals to iron out practical problems thrown up by the protocol for people in Northern Ireland.
Away from the drama playing out right now, there are clear areas like customs lanes where the EU and the UK government aren't far apart at all. But the mood music is dreadful.
European Commission Vice President Maros Sefcovic said renegotiating the protocol is unrealistic and unilateral action by the UK is "damaging to mutual trust".
He said the protocol was the "one and only solution" to protect the peace process in Northern Ireland, while addressing the challenges created by Brexit.
"It is with significant concern that we take note of today's decision by the UK government to table legislation disapplying core elements of the protocol," he said.
"The commission will now assess the UK draft legislation."
The White House press secretary said the US administration recognises "challenges over the implementation of the Northern Ireland Protocol."
"We urge the UK and the EU to return to talks to resolve these differences," the press secretary said.
Businesses which import Great Britain goods to Northern Ireland have experienced difficulties with the protocol as the checks and controls add cost and complexity.
Food and horticulture importers have faced the greatest problems, as those goods face the most onerous controls.
However, exporters, including food exporters, have benefited because unlike other parts of the UK they have maintained frictionless access to EU markets.
Irish Prime Minister Micheál Martin called for negotiations between the UK and EU to deal with the impasse.
Scottish First Minister Nicola Sturgeon said the government's legislation risks a "deeply damaging" trade war with the EU.
Shadow Foreign Secretary David Lammy said it was "a desperate attempt by Boris Johnson to distract from the drama of his leadership crisis".
Meanwhile, Stuart Anderson from the Northern Ireland Chamber of Commerce and Industry said it was ready to play its part in supporting lasting solutions that work for businesses and households.
"While there are attractive elements in today's proposals for consumer facing businesses in particular, a careful balance must be struck to protect gains made to date by our exporters and agri-food sub-sectors," he said.