“I’m pleased to announce the U.S. & our Northern Triangle allies have reached a HISTORIC agreement to confront the root causes of the crisis on our border,” Ms. Nielsen said on Twitter on Wednesday. “Working with Central American govts to increase security & prosperity in the region has been one of my greatest priorities.”

The countries agreed to continue having conversations about ways to counter human trafficking, smuggling, organized crime and gangs, and to improve border security throughout the region.

Mexico’s president, Andrés Manuel López Obrador, said on Thursday that his country was in constant communication with the United States and would maintain “a very respectful relationship” with its neighbor.

It was not immediately clear what caused Mr. Trump’s outrage early Thursday, and later he wrote that “Mexico, with the strongest immigration laws in the World, refuses to help with illegal immigration & drugs!” The remarks came on the heels of House Democrats’ refusal to sign off on a Defense Department request to redirect funds to be used to help build the president’s border wall.

“Instead of focusing on readiness, hurricane recovery and other genuine issues, the administration continues to spend billions of dollars on an imaginary crisis,” Representative Adam Smith of Washington, the chairman of the House Armed Services Committee, said in a statement on Tuesday.