CIUDAD TECÚN UMÁN, Guatemala — After days of walking and hitchhiking, a crowd of migrants rushed a bridge at Guatemala’s border with Mexico on Saturday and clashed with Mexican police who used pepper spray and closed the crossing’s large metal gates to keep them out.

More than 1,000 migrants were trying to cross the bridge spanning the Suchiate River, which delineates a section of the border between Guatemala and Mexico. After calm was restored, small groups of 20 or so migrants, many of them women and children from Central America, were allowed to file through in orderly fashion and register with Mexican migration officials.

The melee was the latest test of President Andres Manuel López Obrador’s resolve to get tougher on undocumented migration and stop the flow of migrants illegally entering Mexico, many of them trying to make their way to the United States.

The governments of Mexico and several Central American countries, the source of many of the undocumented migrants who have sought to cross the southwest border of the United States in recent years, have been under pressure from President Trump to help stem the flow of migrants. Mr. Trump temporarily withheld development aid and threatened tariffs to try to force his counterparts in the region to take a tougher stance.