President Donald Trump said he has a deal with Denmark to bolster the US military presence in Greenland after months of threatening to take the island by force from the NATO ally — an agreement that also keeps the Arctic territory in Denmark’s hands.

Trump, in a social media post announcing the deal, said the agreement “gives the United States permanent control over security, and all other needs, in Greenland, completely addressing ALL of our many US concerns”.

He added that under the agreement his administration would “immediately” begin developing a larger military presence on the mineral-rich Danish territory.

The deal came after officials from the US, Greenland and Denmark quietly negotiated for months behind the scenes, searching for solutions to address some of Trump’s security concerns about a territory of roughly 56,000 residents.

For Trump, the Greenland issue had largely been put on the back burner as he launched a military operation to oust former Venezuelan President Nicolás Maduro from power and joined with Israel to start a war against Iran.

With the announcement of the pact, Trump is able to tout a foreign policy achievement ahead of the midterm elections. The six-month-old Iran conflict has reshaped the race, undermining Trump’s campaign pledge to steer clear of foreign conflicts and challenging Republicans as they cling to narrow majorities in Congress.

The office of Denmark’s prime minister, Mette Frederiksen, said the deal will be signed by three governments next week during the United Nations General Assembly, but parliamentary action is still needed by the Danish and Greenland governments before it can be enforced.

In a statement, she said “the agreement recognises the sovereignty and territorial integrity” of Greenland and Denmark and upholds both peoples’ right “to self-determination”.

Greenland Prime Minister Jens-Frederik Nielsen said the emerging deal benefits all three governments and “recognises Greenland’s interests”.

Allies pushed back on Trump’s call for the US to acquire Greenland

President Donald Trump speaks during an event about healthcare in the Oval Office of the White House.

With his return to the White House last year, Trump called on Denmark to sell the island to the United States, while insisting that Greenland is crucial for US security. He pointedly wouldn’t rule out taking the island by military force, even though Denmark is a NATO ally of the US.

Denmark and Greenland repeatedly said the island is not for sale and condemned reports of the US gathering intelligence there. The US push for Greenland is also opposed by Russia and much of Europe.

But Trump, in his social media post Friday, suggested an understanding may have been reached that could bring an end to what was viewed as an existential crisis by Denmark.

“We look forward to working with the wonderful people of Denmark and Greenland toward a magnificent future with respect to this large, and highly strategic, parcel of land,” Trump said in his post. “We will be very protective of it!”

Trump had raised concerns that Russia and China had become more active in the Arctic, making the need for the US to take control of Greenland necessary.

But the agreement bans any non-NATO base in Greenland, limits adversaries from being able to make investments in Greenland and guarantees that China and Russia cannot have a base in Greenland, according to a State Department official who was not authorised to comment publicly and spoke on the condition of anonymity.

Secretary of State Marco Rubio cheered the statement as a “historic deal” and “huge win” for the United States.

“Greenland will forever be part of the strategic defence area of North America and exclude any adversary from it and the surrounding area,” Rubio said. “This deal permanently and completely addresses our national security concerns in Greenland.”

The island is crucial to North America’s defence

Houses covered in snow are seen on the coast of a sea inlet of Nuuk, Greenland

But the US has long had a military presence in Greenland, holding several bases and installations through the Cold War before dialling back its presence.

The US still operates the remote Pituffik Space Base in northwestern Greenland, which was built after the US and Denmark signed the Defence of Greenland Treaty in 1951. It supports missile warning, missile defence, and space surveillance operations for the US and NATO.

Greenland sits off the northeastern coast of Canada, with more than two-thirds of its territory lying within the Arctic Circle. That has made it crucial to the defence of North America since World War II, when the U.S. occupied Greenland to ensure it didn’t fall into the hands of Nazi Germany and to protect vital North Atlantic shipping lanes.

Despite Trump’s repeated aggressive comments toward Denmark about Greenland, Danish officials had repeatedly made clear that they stood ready to work with the US to expand the American military presence and strengthen US commercial interests in Greenland.

Still, Trump’s repeated demands for Greenland and threats to take it by force rattled the NATO alliance and discomfited European allies, said Imran Bayoumi, an associate director at the Atlantic Council’s Scowcroft Centre for Strategy and Security.

“I think Americans really underestimate how damaging it was for the image of the United States in Europe,” he said. “I think Greenlanders, Danes, and Europeans saw this as a real attack on their sovereignty, and it’s going to take a lot of work to repair.”