Mexico will deport up to 500 migrants who attempted to storm the US border, according to its interior ministry.
The group were rounded up after trying to cross the border “violently” and “illegally” on Sunday, the ministry said in a statement.
Video footage shows dozens of people – including women and children – running towards the fence that separates the two countries near the city of Tijuana.
US border officers used tear gas to repel them.
Mexico’s interior ministry said in a statement that a group of “nearly 500 migrants” had “tried to cross the border in a violent way”.
Those identified as having taken part in these “violent events” would be deported immediately, it said.
The ministry added that, “far from helping their objectives”, the migrants’ actions had violated the legal migration framework and could have led to a “serious incident”.
Tensions have been high in Tijuana since the arrival of thousands of migrants earlier this month.
They reached Tijuana after travelling more than 4,000km (2,500 miles) from Central America.
They say they are fleeing persecution, poverty and violence in their home countries of Honduras, Guatemala and El Salvador.
However, they now face a long wait to see if their asylum applications will be accepted by the US, with President Donald Trump vowing to keep each migrant on the Mexican side of the border until courts have decided their case. This could take months.
Amid growing desperation on Sunday, about 500 migrants were taking part in a peaceful protest for the right to seek political asylum in the US.
“We aren’t criminals! We are hard workers,” they chanted.
Mexico’s Home Secretary, Alfonso Navarrete, said the migrants had asked for help to organise the demonstration, but were then reportedly encouraged by some of the movement’s leaders to split into different groups so they could make a run for the border and try to cross into the US.
A darker mood
It was a day of some drama in Tijuana. After two frustrating weeks in their temporary camp in a municipal sports centre, about 500 migrants joined the peaceful march, carrying banners and chanting pro-migrant slogans.
Once they managed to get past the security cordon, though, it quickly turned into a dash for the border.
Unsurprisingly, they were met with force. Tear gas was fired and the US and the Mexican authorities closed the San Ysidro border crossing .
That caused long delays in both directions and angered people like Jose Fajardo. Like many residents of Tijuana, he lives on the Mexican side but works in the US city of San Diego.
“It’s really bad,” he said, motioning at the backed-up traffic and lines of riot police. “I have to get to work in a restaurant over the other side. I cross the border every day for work. But when you can’t work, there’s no money.”
Yet even as they were being forced back by riot police, plenty of migrants on the march felt the effort to raise their voice had been necessary.
“Maybe Donald Trump could give us an opportunity. We came here to work, not to create problems or crime,” said Roberto, a Honduran attempting this journey in his late 60s.
Now the Mexican government has said that anyone who took part in the protest will be deported, a threat that has undoubtedly unsettled people in the caravan. From a bright morning as the march left the camp, the mood has darkened in the knowledge that at least some among their number will be sent home simply for having joined in.
According to news agency AFP, a number managed to climb over the first fence. It was as they tried to cross a second, spike-topped wall that officials on the US side began firing tear gas.
An AFP journalist saw the migrants – including mothers and children – trying to protect themselves from the gas, with some crying out that they only wanted to find a work and a better life in the US.
Honduran migrant Ana Zuniga, 23, tried to cross with her three-year-old. She told AP: “We ran but when you run, the smoke smothers you more.”
Another Honduran, Joseph Garcia, told Reuters news agency he could not bear the wait any longer.
“I, for one, am desperate. My little girl is sick and I don’t even have money for milk,” he said. “I can’t stand it anymore.”
As a result of Sunday’s action, the US closed the San Ysidro border crossing near Tijuana to vehicles and pedestrians for a time before re-opening it.
Mr Trump threatened to close the entire US-Mexico border earlier this week if it was felt the US was going to “lose control” of the situation.
He also said he had given troops at the border the go-ahead to use lethal force if needed.
Mr Trump has deployed about 5,800 troops to the border. He previously described the migrants as an “invasion”.
Lt Gen Jeffrey Buchanan told Politico last week that some of engineering and logistic troops were already beginning to leave after completing work erecting new security structures.
Pentagon officials have previously said the mission would be over before Christmas.