The G7 summit ended in farce and a renewed threat of global trade war on Saturday as US president Donald Trump abruptly rejected the text of a consensus statement and bitterly insulted the Canadian host.

Just minutes after a joint communique that had been approved by the leaders of the Group of Seven allies was published in Canada's summit host city Quebec, Trump launched a Twitter broadside from aboard Air Force One.

The US leader had left the meeting early en route for Singapore and a historic nuclear summit with North Korea's Kim Jong Un, only to take exception to comments made by Canada's prime minister Justin Trudeau at a news conference back on the ground.

"Based on Justin's false statements at his news conference, and the fact that Canada is charging massive Tariffs to our US farmers, workers and companies, I have instructed our US Reps not to endorse the Communique as we look at Tariffs on automobiles flooding the US Market!" Trump tweeted.

"PM Justin Trudeau of Canada acted so meek and mild during our @G7 meetings only to give a news conference after I left saying that ... he 'will not be pushed around.' Very dishonest & weak."

- 'Pushed around' -

Earlier, Trudeau had told reporters that Trump's decision to invoke national security to justify US tariffs on imports of steel and aluminium was "kind of insulting" to Canadian veterans who had stood by their US allies in conflicts dating back to World War I.

"Canadians are polite and reasonable but we will also not be pushed around," he said.

And he said he had told Trump "it would be with regret but it would be with absolute clarity and firmness that we move forward with retaliatory measures on 1 July, applying equivalent tariffs to the ones that the Americans have unjustly applied to us."

After Trump's angry tweets, Trudeau's office issued a brief response: "We are focused on everything we accomplished here at the G7 summit. The prime minister said nothing he hasn't said before -- both in public, and in private conversations with the president."

The outburst against Trudeau, and by association the other members of the G7 group, is only the latest incident in which Trump has clashed with America's closest allies, even as he has had warm words for autocrats like Kim and Russia's Vladimir Putin.

This has raised concerns at home and abroad, and shortly after Trump tweeted respected Republican Senator John McCain responded.

"To our allies: bipartisan majorities of Americans remain pro-free trade, pro-globalisation & supportive of alliances based on 70 years of shared values. Americans stand with you, even if our president doesn't," he tweeted.

When Trump left Quebec it was thought that a compromise had been reached, despite the tension and determination of European leaders president Emmanuel Macron of France and chancellor Angela Merkel of Germany to push back on Trump's assault on the world trade system.

Officials from European delegations quickly leaked copies of the joint statement to AFP, and it was published online moments before Trump tweeted. Copies that begin "We, the Leaders of the G7..." were distributed in the press room stamped "Approved."

On board Air Force One an AFP reporter was first told that Trump had indeed approved the agreement, only to be told later of the tweets. A senior administration official told the reporter that Trump had been angered by Trudeau's comments.

The outburst suggested that any deal had collapsed and his more or less explicit threat to impose sanctions on imports of cars will outrage his ostensible allies -- in particular Germany and Canada who produce many for the large US market.

In retrospect, the consensus on ground had appeared shaky from the outset, and even as Trump flew out it was clear that the summit had failed to heal the rift on trade.

Trump claimed America had been obliged to levy the metals tariffs as it has been exploited as the world's "piggy bank" under existing arrangements, but his counterparts were equally determined to protect "rules-based" international trade.

- 'The gig is up' -

The joint communique that was thrashed out over two days of negotiations vowed that members would reform multilateral oversight through the World Trade Organisation (WTO) and seek to cut tariffs.

"We commit to modernise the WTO to make it more fair as soon as possible. We strive to reduce tariff barriers, non-tariff barriers and subsidies," it said, reflecting the typical language of decades of G7 statements.

But Trump had already said he would not hesitate to shut countries out of the US market if they retaliate to his tariffs.

"The European Union is brutal to the United States ... They know it," he insisted in his departing news conference. "When I'm telling them, they're smiling at me. You know, it's like the gig is up."

European officials said Trump had tried to water down the language in the draft communique on the WTO and rules-based trade. In the end, that language stayed in and it was only on climate change that no consensus was reached.

European leaders had put a brave face on the results.

"For us, it was important to have a commitment to rules-based trade," Germany's chancellor Angela Merkel said, before Trump's comments.

French president Emmanuel Macron, whose country will host next year's summit in summer in the Atlantic resort of Biarritz, had no comment on Trump's tweets but had already said work would continue to find a consensus on trade.-AFP