Many of the migrants were fleeing violence by criminal gangs.

Mexico said on Thursday that it rejected attempts at pressure after US President Donald Trump threatened to close his country's southern border to stop an "onslaught" of migrants, including a caravan waiting on the Mexican border to cross into the United States.

Mexican Interior Minister Alfonso Navarrete said in parliament that he wanted to tell the US government "with all clarity" that "we reject any attempt at pressure to change our legislative framework, because we won't do it."

The Mexican government also said it would ask the UN refugee agency UNHCR to help it handle the caravan and to find a "humanitarian" solution for the migrants.

Trump accused Guatemala, Honduras and El Salvador of doing little to stop the flow of migrants from entering Mexico. He had on Wednesday criticized the three Central American countries and threatened to cut aid if they fail to stop the migrants.

On Thursday, he went a step further, saying on Twitter that in addition to stopping aid, he would order the US military to close the border.

"In addition to stopping all payments to these countries, which seem to have almost no control over their population, I must, in the strongest of terms, ask Mexico to stop this onslaught - and if unable to do so I will call up the US Military and CLOSE OUR SOUTHERN BORDER!" Trump wrote.

He said the "assault on our country" at the border includes "criminal elements" and drugs and is more important to him than the recently concluded trade deal. The president also linked the migration problem to opposition Democrats.

"Hopefully Mexico will stop this onslaught at their Northern Border. All Democrats fault for weak laws!" Trump said.

The president made the comments ahead of US Secretary of State Mike Pompeo's visit to Mexico on Friday.

Mexico has put extra police on its border with Guatemala in preparation for the arrival of the migrant caravan, estimated to include between 1,500 and 3,000 people, which left northern Honduras on Saturday.

Mexico has announced that it will not allow the entry of people without the necessary documents.

Navarrete said that not all the migrants would meet the criteria needed for them to be granted refugee status, but that Mexico would try to grant "humanitarian protection and human rights" to the largest possible number.

Officers deployed on the border will not "repress" the migrants, police chief Manelich Castilla told the broadcaster Foro TV, adding they had only been instructed to "contain" the caravan.

Mexico wanted to avoid the kind of situation that had occurred in Guatemala, where the migrants lifted a security barrier to cross the border, Castilla said, adding that police wanted to help the migratory authorities maintain "order."

Hundreds of migrants were meanwhile waiting in the Guatemalan border town of Tecun Uman for the rest of the caravan to arrive and to cross over to Mexico.

Migrants including women and children were sitting on benches or resting on the ground with their bags and water bottles.

"I want to stay in Mexico and to possibly bring my family," said one of them, who identified himself as Christopher.

Many of the migrants were fleeing violence by criminal gangs, he said. "If you start a business, you need to pay the criminals, and the government affords you no protection."

"Jobs are badly paid and there is a lot of exploitation" in Honduras, said Ana Raquel Hernandez, another migrant.