Mr Trump said the US paid “close to the entire cost of Nato” to help protect countries that “rip us off on trade”.
“Fair trade is now to be called fool trade,” he added in response to the threat of new tariffs against the US.
Canadian Prime Minister Justin Trudeau has vowed retaliatory action next month over US tariffs on steel and aluminium.
Mr Trump has also attacked Mr Trudeau personally, suggesting the Canadian prime minister is “very dishonest and weak” and “acts hurt when called out”.
By Jon Sopel, BBC North America editor
In Quebec at the G7 the sherpas, political advisers and draftsmen toiled through two nights to find a form of words that all sides could sign up to.
I left before the end of the summit to embark on a marathon journey from Canada to Singapore.
When I left Quebec all the talk was there would be no agreement. But lo, by the time I landed in Hong Kong to change flights I read that there was a joint communique. Success. Only to see a tweet from Donald Trump a little later rescinding his signature over something Justin Trudeau had said at his news conference. Unbelievable.