WASHINGTON — President Trump on Friday again sought to block migrants from Central America from seeking asylum, announcing an agreement with Guatemala to require people who travel through that country to seek refuge from persecution there instead of in the United States.

American officials said the deal could go into effect within weeks, though critics vowed to challenge it in court, saying that Guatemala is itself one of the most dangerous countries in the world — hardly a refuge for those fleeing gangs and government violence.

Mr. Trump had been pushing for a way to slow the flow of migrants streaming across the Mexican border and into the United States in recent months. This week, the president had threatened to impose tariffs on Guatemala, to tax money that Guatemalan migrants in the United States send back to family members, or to ban all travel from the country if the agreement were not signed.

Joined in the Oval Office on Friday by Interior Minister Enrique Degenhart of Guatemala, Mr. Trump said the agreement would end what he has described as a crisis at the border, which has been overwhelmed by hundreds of thousands of families fleeing violence and persecution in El Salvador, Honduras and Guatemala.