MEXICO CITY — President Donald J. Trump’s decision to build a wall along the southern border escalated into a diplomatic standoff on Thursday, with Mexico’s president publicly canceling a scheduled meeting at the White House and Mr. Trump firing back, accusing Mexico of burdening the United States with illegal immigrants, criminals and a trade deficit.

Mr. Trump’s push to fulfill his campaign pledge and build a border wall brought to a head months of simmering tensions, culminating in a remarkable back-and-forth between the two leaders.

By afternoon, Mr. Trump’s spokesman said the president would pay for the border wall by imposing a 20 percent tax on imports to the United States, which he said would raise billions of dollars.

The sparring began Thursday morning when the president of Mexico announced on Twitter that he was canceling his meeting with Mr. Trump next week, rejecting the visit after the new American leader ordered the border wall between the two nations.