ODENSE, Denmark — The astonishment in Denmark over President Trump’s apparent desire to buy Greenland turned to bewilderment and anger on Wednesday after the American leader abruptly scrapped a state visit because the Danes have no desire to sell.

The cancellation was a rare snub of Denmark’s head of state, Queen Margrethe II, who had extended the invitation to the president and would have hosted him and the first lady.

Mr. Trump further strained ties on Wednesday, calling the Danish prime minister’s rejection of the idea “nasty.”

News that Mr. Trump had called off his visit “came as a surprise,” the Royal House’s communications director told the state broadcaster, adding, “That’s all we have to say about that.”