TIJUANA, Mexico — American authorities used tear gas on hundreds of migrants who tried to enter the United States illegally Sunday, prompting officials to shut down operations at the border crossing between this city and San Diego, one of the busiest in the world.

U.S. Customs and Border Protection suspended all vehicles and pedestrians from passing through the San Ysidro Port of Entry at 11:30 a.m. after the migrants tried to cross on either side of the inspection station.

San Ysidro was reopened shortly after 6 p.m., the agency said.

Some migrants said they tried crossing only after being denied access to the port of entry where they could claim asylum.

A migrant family runs away from tear gas near the border wall between the U.S and Mexico in Tijuana on Sunday. Kim Kyung-Hoon / Reuters

Customs and Border Protection said in a statement that it used tear gas and pepper spray after several migrants threw rocks at border agents, striking them.

No injuries were reported, the agency said.

"DHS will not tolerate this type of lawlessness and will not hesitate to shut down ports of entry for security and public safety reasons," Department of Homeland Security Secretary Kirstjen Nielsen said Sunday in a statement.

The shutdown came after hundreds of migrants — many whom are fleeing violence in Central America — assembled Sunday morning on the Mexican side of the border. American military helicopters buzzed overhead as hundreds of Mexican federal police officers blocked the migrants from entering San Ysidro.

Over 1,000 migrants have stormed past riot police to get to the US border through the Tijuana River #MigrantCaravan pic.twitter.com/bf2ZsLxRqq — Annie Rose Ramos (@Annie_Rose23) November 25, 2018

The migrants were part of a larger group of roughly 6,000 who’d crammed into several shelters in Tijuana — a situation the city’s mayor has called a “humanitarian crisis.”

In an interview Sunday, one of the migrants, Jorge Montoya, 43, described thousands of people staying in a rundown sports stadium with overflowing toilets. He and others called the conditions intolerable — but when Mexican authorities refused to grant them access to the port of entry, hundreds slogged across the sewage-laden Tijuana River in search of access to the United States.

Migrants run from tear gas near the border fence in Tijuana, Mexico, on Sunday. Hannah McKay / Reuters

Among the throng were elderly people in wheelchairs and children with strollers. The group formed a human chain along the river’s steep embankments.

“We’re not running because we’re criminals,” Montoya said. “We’re running from the crime in our country.”

On the other side of the river, dozens of migrants broke through a wooden fence and climbed atop a freight train. Clutching Honduran and Guatemalan flags, they could see the United States from their perch — but there still appeared to be no way for them to cross.

Mexico’s incoming Secretary of the Interior, Sen. Olga Sánchez Cordero, said in a statement Sunday that authorities were working to identify nearly 500 migrants who tried to enter the United States in a "violent way."

Those who are found will be immediately deported, she said.

The attempted crossing came after Trump administration officials and members of Mexico’s incoming government appeared to be at odds over a deal that could prevent asylum-seekers from entering the United States.

Under the current system, asylum-seekers can remain in the U.S. while their cases are processed in American courts. But the Trump administration wants them to remain in Mexico instead.

Two Trump administration officials told NBC News that the plan was a few weeks away from going into effect, though Jesus Ramirez Cuevas, a spokesman for recently elected Mexican President Andrés Manuel López Obrador, said no such agreement had been reached.

Last month, President Donald Trump ordered about 5,800 troops to the border, a number he has suggested could more than double. They joined the 2,000 troops already stationed there, in addition to thousands of border patrol agents.

Annie Rose Ramos reported from Tijuana, Mexico. Tim Stelloh reported from Alameda, California.