HAMBURG—Through marathon meetings and dinners at the Group of 20 summit, various world leaders sought to coax America’s new president to accept core tenets of the internationalist order they embrace, including commitment to free trade and tough environmental regulation.

He barely budged. In his second foreign trip, President Donald Trump largely held firm to the nationalist principles that were central to his campaign identity, suggesting that the America First doctrine that underpins his foreign policy is more durable than...