The US and Guatemala have signed a migration agreement, days after US President Donald Trump threatened the Central American country with tariffs.

Under the deal, migrants from Honduras and El Salvador who pass through Guatemala would be required to stop and seek asylum there first.

Migrants who failed to do so would then be ineligible for asylum in the US. Mr Trump said that in exchange Guatemalan farm workers would get easier access to work on US farms.

The Guatemalan government says the agreement will last for two years, and will be reviewed every three months. It said neither side was obliged to make any funding available under the plan.

Guatemala's President Jimmy Morales had been due to sign a deal with Mr Trump last week when the Guatemalan Constitutional Court ruled he could not sign without approval from Congress.

Mr Trump responded by threatening Guatemala with tariffs, remittance fees and other sanctions after the country's high court issued its order blocking the agreement.

"We were ready to go. Now we are looking at the "BAN,".... Tariffs, Remittance Fees, or all of the above. Guatemala has not been good. Big US taxpayer dollars going to them was cut off by me 9 months ago," Mr Trump wrote on Twitter.

A tax on Guatemalan remittances would have posed a significant threat the nation's economy. Guatemalan nationals living abroad sent back $9.5 billion (£7.4bn; €8.2bn) in 2018 - 12% of the country's GDP, according to the World Bank.

Responding to the Guatemalan Constitutional Court decision to block last week's proposed deal, President Morales said on Twitter: "All this jeopardizes the bilateral relationship with the United States that will lead to possible sanctions."

It was not immediately clear how, or if the Guatemalan Constitutional Court ban on signing a deal had been circumvented, but the Guatemalan government's statement on the deal notably did not refer to it as a "safe third country agreement" - which had been referred to last week.

The sanctions threats issued by Mr Trump echoed his treatment of Mexico. Last month he said he would impose steadily increasing tariffs - starting at 5% and climbing to 25% - if it did not take greater steps to stem migration to the US.

Mr Trump said he abandoned the tariffs when Mexico agreed to strengthen patrols on the border. Before Friday's deal with Guatemala, migrants arriving at the US-Mexico border were allowed to request asylum regardless of which country they passed through to get there - although the Trump administration had placed heavy restrictions on the number of people allowed to apply.

Under the 1951 UN Refugee Convention, there is no obligation on refugees to claim asylum in the first safe country they reach. Asylum seekers are protected against prosecution for illegal entry to a foreign country by Article 31 of the Convention.

Guatemala, as well as its southern neighbours El Salvador and Honduras, has been struggling to curb the flow of people leaving for the US.