President Donald Trump has signed a new security agreement with Denmark and Greenland, ending months of tension.