Two Mexican nationals have been charged in US federal court in connection with a deadly human smuggling attempt in which at least 51 people perished after being trapped inside a sweltering tractor-trailer truck in San Antonio, Texas.

The two defendants, who were arrested following yesterday's incident, were charged with possessing firearms while in the United States illegally, according to court documents and US authorities.

The deceased migrants, 39 men and 12 women, were discovered on the outskirts of the south Texas city, where temperatures swelled to a high of 39.4C in one of the deadliest human trafficking tragedies in recent history.

Authorities called to the scene found the truck parked next to railroad tracks, with bodies inside the vehicle and strewn over a couple of blocks.

The rear door of the trailer had been opened, a local law enforcement official told Reuters.

Authorities said there were no signs of water and no visible working air conditioning inside the truck. Officials said there were "stacks of bodies" and that some of the migrants were hot to the touch.

The US Department of Homeland Security announced it had opened a criminal investigation, as President Joe Biden took aim at human smuggling gangs.

"The tragic loss of life in San Antonio, Texas that took place yesterday is horrifying and heartbreaking," he said in a statement.

"This incident underscores the need to go after the multi-billion dollar criminal smuggling industry preying on migrants and leading to far too many innocent deaths," he said.

According to Mexican President Andres Manuel Lopez Obrador, of the dead whose identities are known, 22 were from Mexico, seven from Guatemala and two from Honduras.

"It's a tremendous misfortune," he told reporters.

By this afternoon, authorities had removed the trailer from where it had been abandoned with its human cargo, on a narrow road sandwiched between train tracks and auto junkyards.

Replacing it were makeshift crosses adorned with artificial flowers.

"I feel that if these people walk hundreds of miles to get over here, it wouldn't hurt us to walk maybe one mile to put the crosses and candles," said Angelita Olvera, who lives nearby.

"Hopefully, whoever had them in the trailer will pay the consequences," she said.

San Antonio Police Chief William McManus said authorities were first alerted to the trailer by an emergency call at about 5:50 pm local time on Monday.

"A worker who works in one of the buildings up here behind me heard a cry for help," he told reporters.

The worker "came out to investigate, found a trailer with the doors partially open, opened them up to take a look, and found a number of deceased individuals inside," Chief McManus said.

Three people have been taken into custody but officials gave no further details.

The tragedy came five years after 10 migrants were found dead in a trailer with broken air conditioning and clogged ventilation holes near San Antonio.

In recent weeks Border Patrol officers have discovered other attempts to bring undocumented travelers into the country in large trucks.

In this aerial view, members of law enforcement investigate a tractor trailer in San Antonio, Texas

On 14 June, 80 people from Mexico, Guatemala, Honduras and El Salvador were discovered inside a tractor-trailer when it was inspected by agents at a highway checkpoint north of Laredo, a border hub in south Texas.

Under President Biden more than 200,000 people attempting to enter the country illegally have been intercepted at the border each month and sent back.

But there is no good estimate of the thousands more that succeed in staying inside the country.

Mr Biden said he had already launched an anti-smuggling campaign that focused on the networks and arrested 2,400 people in recent months.

"Exploiting vulnerable individuals for profit is shameful, as is political grandstanding around tragedy," he said.

Police and reporters stand near the scene where the tractor-trailer was discovered

The migration issue will be a key agenda item when Joe Biden hosts Mexican counterpart Lopez Obrador for talks on 12 July.

Meanwhile a Texas official said some of the victims who died inside the truck were potentially under 18 - "in the teenage age range".

Mexico's Foreign Minister Marcelo Ebrard called the suffocation of the migrants in the truck the "tragedy in Texas" on Twitter and said consular officials would go to the hospitals where victims had been taken to help "however possible".

A spokesman for the Honduran foreign ministry said the country's consulates in Houston and Dallas would be investigating the incident.

The I-35 highway near where the truck was found runs through San Antonio from the Mexican border and is a popular smuggling corridor, due to the large volume of truck traffic.

That is according to Jack Staton, a former senior official with ICE's investigative unit who retired in December.