Images of a drowned Salvadoran migrant and his two-year-old daughter who died while trying to cross the Rio Grande river from Mexico to the United States have sparked outrage, underscoring the dangers faced by asylum-seekers.

Oscar Martinez Ramirez, 25, fled El Salvador with his 21-year-old wife and their daughter and decided to make the risky crossing from Mexico to the US on Sunday, according to a Mexican court report seen by AFP.

Mr Ramirez carried the little girl on his back, stowing her inside his t-shirt to keep her safe as they attempted to cross the river.

But the pair were swept away by violent currents. Mr Ramirez's wife, who survived the crossing, witnessed their deaths.

The two bodies were found on Monday in Matamoros in Tamaulipas state.

A series of photographs showing the young father and child lying face-down in water have stirred anger in El Salvador and Mexico, where the government had faced sharp criticism for its treatment of migrants.

President Andres Manuel Lopez Obrador, who took office in December vowing to protect migrants' rights, has previously come under fire over an AFP journalist's images last week of heavily armed National Guardsmen forcibly detaining two women and a girl at the Rio Grande.

Yesterday, he said the 15,000 troops his government has deployed to the US border do not have orders to stop migrants from crossing, and vowed to investigate the controversial detention.

Read More:

Aid package approved for migrants 
US relocates migrant children over squalid conditions 
Mexico publishes Trump's 'secret deal' on migration

International law protects the right of undocumented migrants to cross borders to seek asylum, and Mexico has not typically stopped them from doing so at its northern border.

But Mr Lopez Obrador is facing pressure from US President Donald Trump on the issue, and his government is eager to show results and avoid the punitive tariffs the US leader threatened last month to impose on Mexican goods.

On 7 June, the two countries reached an agreement, with Mexico agreeing to reinforce its southern border with 6,000 National Guardsmen.

The US has given Mexico 45 days to take action.

The UN refugee agency said the photo symbolises the failure to deal with their desperation.

"UNHCR … is deeply shocked to see the heart-breaking photo of the drowned bodies of Oscar Alberto Martinez Ramirez and his 23-month-old daughter Valeria from El Salvador washed up on the banks of the Rio Grande," it said in a statement.

UN High Commissioner for Refugees Filippo Grandi said they had risked their lives because they could not get the protection they were entitled to under international law.

"The deaths of Oscar and Valeria represent a failure to address the violence and desperation pushing people to take journeys of danger for the prospect of a life in safety and dignity," he said in the statement.

UNHCR compared it with the iconic photograph of a Syrian refugee toddler, Alan Kurdi, washed up on the shores of the Mediterranean in 2015.

He was part of a Syrian refugee wave that caused panic in Europe, prompting Turkey to effectively shut down the migrant route through Greece at the European Union's behest.

Since then, many countries have erected barriers to migrants and some, like the European Union and the United States, have pressured their neighbours to cut the numbers of people trying to make the journey.