Donald Trump has made cracking down on illegal immigration a keystone of his presidency,

US President Donald Trump threatened Thursday to send the military to close its southern border if Mexico fails to stem the "onslaught" of migrants from Central America, in a series of tweets that blamed Democrats ahead of the midterm elections.

The attack comes with Trump's Republicans fighting to retain control of Congress in the November 6 vote, and as thousands of migrants from impoverished Honduras were marching north through Guatemala toward the United States.

"I am watching the Democrat Party led (because they want Open Borders and existing weak laws) assault on our country by Guatemala, Honduras and El Salvador, whose leaders are doing little to stop this large flow of people, INCLUDING MANY CRIMINALS," Trump said.

"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 U.S. Military and CLOSE OUR SOUTHERN BORDER!"

The tweets came as Secretary of State Mike Pompeo prepared to embark on a tour of the region that will see him visit Mexico ahead of its December inauguration of President-elect Andres Manuel Lopez Obrador, as well as Panama.

Trump has made cracking down on illegal immigration and building a wall that stretches the length of the 1,954-mile (3,145 km) border a keystone of his presidency, but his animus toward Mexico had cooled since Obrador's election in July.

Despite their sharp differences, the US and Mexico have made progress on several issues, including the signing of an updated transcontinental trade pact, the US-Mexico-Canada Agreement (USMCA).

But, possibly with an eye on November 6 polls that will determine whether Republicans retain control of Congress, Trump returned to the fiery rhetoric that has marked his past relations with Mexico.

"The assault on our country at our Southern Border, including the Criminal elements and DRUGS pouring in, is far more important to me, as President, than Trade or the USMCA," he said.

Caravan presses on

It was not immediately clear what form of military deployment Trump had in mind. The president announced plans in April to send thousands of National Guard troops to the border, where they could remain until his promised wall is constructed.

At least five US states later refused to send the troops amid an outcry over a policy to separate migrant children from their parents, since discontinued.

Exhausted after tramping in the sun and rain, an advance group of the Honduran migrants on Wednesday took refuge in a church-sponsored shelter in the center of Guatemala City.

Their objective now is to regroup and press on towards the border with Mexico.

A caravan of vehicles carrying more than 2,000 migrants left last Saturday from the northern Honduran city of San Pedro Sula after organizing themselves on social media.