US Border Patrol agents fired tear gas to repel rock-throwing migrants who tried to storm through a border fence separating California and Mexico on Sunday.

Some of the migrants, part of the caravan that traveled to the border from Central America, threw “projectiles” at border agents as they approached the fence, officials said. Video appeared to show rocks being thrown.

US Customs and Border Protection later tweeted that several agents were struck and tear gas was used “to dispel the group because of the risk to agents’ safety.”

Children in the group were screaming and coughing amid the chaos, which a witness said erupted when some migrants cut a hole in concertina wire on the Mexican side of a levee.

“We ran, but when you run, the gas asphyxiates you more,” Honduran migrant Ana Zuniga, 23, told the Associated Press while cradling daughter Valery, 3, in her arms.

Homeland Security Secretary Kirstjen Nielsen said her department “will not tolerate this type of lawlessness and will not hesitate to shut down ports of entry for security and public safety reasons.”

“We will also seek to prosecute to the fullest extent of the law anyone who destroys federal property, endangers our frontline operators, or violates our nation’s sovereignty,” she added.

Mexico’s Interior Ministry said it would deport almost 500 migrants who were rounded up after trying to “violently” and “illegally” cross the border, according to the BBC.

The confrontation came after a caravan of several hundred Central American migrants — including women pushing kids in strollers — overwhelmed Mexican cops standing guard near the San Ysidro crossing that links San Diego with Tijuana, Mexico.

The group breezed by the blockade, carrying hand-painted Honduran and American flags and chanting, “We are not criminals! We are international workers!”

That move prompted the US to suspend all border crossings at San Ysidro around 11:30 a.m. local time, leading some migrants to split off and “head towards multiple locations along the border,” according to a statement from Customs and Border Protection.

“Some attempted to illegally enter the US through both the northbound and southbound vehicles lanes at the port of entry itself. Those persons were stopped and turned back to Mexico,” the CPB added.

Images and videos posted online showed scores of migrants rushing toward the border.

A scuffle broke out when Mexican police in riot gear blocked dozens of migrants who rushed across a canal, according to the Washington Post.

Nielsen said officials were forced to close the San Ysidro crossing “to ensure public safety in response to large numbers of migrants seeking to enter the US illegally.”

She also vowed that federal and local law enforcement agencies — as well as the US military — “will continue to have a robust presence along the Southwest Border and at our ports of entry to prevent illegal entry or violence.”

Earlier this month, President Trump suggested that military troops deployed to the border could shoot rock-throwing migrants, but reversed those remarks a day later.

The border clash came hours after Trump called on America’s southern neighbors to keep the migrants from trying to enter the US.

“Would be very SMART if Mexico would stop the Caravans long before they get to our Southern Border, or if originating countries would not let them form (it is a way they get certain people out of their country and dump in U.S. No longer). Dems created this problem. No crossings!” he tweeted.

More than 5,000 migrants who traveled in caravans through Mexico are camped out in and around a sports complex in Tijuana, with plans to apply for asylum in the US.

But officials at the San Ysidro crossing have been processing fewer than 100 asylum petitions a day, and Tijuana Mayor Juan Manuel Gastelum declared a humanitarian crisis on Friday.

Ireneo Mujica of the aid group Pueblo Sin Fronteras — Spanish for “Town Without Borders” — said Sunday’s march toward the border was supposed to illustrate the migrants’ desperate plight.

“We can’t have all these people here,” Mujica told AP.