Image copyright AFP Image caption The initial bid for the Saudi contract was placed in 2014, before Michael Gove became the justice secretary

The UK government has withdrawn from a controversial £5.9m prisons deal with Saudi Arabia, Downing Street has said.

The PM's official spokeswoman said it reflected the government's decision to focus on domestic priorities.

The deal was to provide a "training needs analysis" for Saudi prison service staff.

No 10 stressed pulling out of the deal was unconnected to the case of expat Karl Andree, jailed in Saudi Arabia after being caught with homemade wine.

It was thought 74-year-old Mr Andree, who has been in jail for more than a year, was facing 360 lashes but the BBC now understands a flogging was never on the cards.

Despite withdrawing from the prison deal, Justice Secretary Michael Gove insisted Britain would maintain its relationship with the country.

Answering an urgent question in the Commons, Mr Gove said: "And while we would never compromise on our commitment to human rights, we must also recognise that it's in the interests of the most important human right of all, the right to live in safety and security, that we should continue with necessary security co-operation with the Saudi government and with other governments."

'Shamed'

The withdrawal follows reports of a cabinet rift on the issue, with Mr Gove said to have angered Foreign Secretary Philip Hammond by seeking to pull the plug.

The Times says the justice secretary wanted to pull out of the deal, saying the government should not be assisting a regime that uses beheadings, stoning, crucifixions and lashings to punish its citizens.

But Mr Hammond warned that cancelling it would not be in the national interest as it would make Britain appear an untrustworthy ally - and No 10 had sided with him, the paper reports.

Downing Street said there would be no financial penalties for pulling out of the bid process.

Analysis

Image copyright PA Image caption Karl Andree

by Frank Gardner, BBC security correspondent

Saudi officials say they are baffled by the headlines suggesting that an elderly Briton, Karl Andree, may face flogging for possessing alcohol.

They say that was never even a possibility because of his age and ill health.

The Saudis are unlikely to be troubled by the cancellation of a very small contract for Britain's Ministry of Justice to give training advice to Saudi prisons - £6m is nothing compared to the multi-billion dollar arms and oil deals regularly concluded with international partners.

France today announced a £7bn deal with Saudi Arabia.

But what the Saudis dislike intensely is public scrutiny of their much-criticised human rights record.

When this escalates into personal intervention by Western leaders, such as David Cameron, it encourages some senior Saudis to look elsewhere for trading partners.

The Saudis are fiercely defensive of their justice system, saying its harsh punishments are based on Sharia, Islamic law. But the way justice is meted out is often considered arbitrary, opaque and disproportionate to the offence.

Labour leader Jeremy Corbyn, who used his recent conference speech to call for the prisons deal to be scrapped, said the government had been "shamed" into the "U-turn on this terrible contract".

"We should be sending a strong message to repressive regimes that the UK is a beacon for human rights and that this contract bid is unacceptable in the 21st Century, and would damage Britain's standing in the world," he said.

Kate Higham, from human rights organisation Reprieve, said cancelling the bid had "sent a clear message that the UK does not support Saudi Arabia's gross violations of human rights".

Image copyright Getty Images Image caption Jeremy Corbyn has been highly critical of Saudi Arabia and its human rights record

The prisons bid was submitted by the now defunct commercial arm of the Ministry of Justice, Just Solutions international (JSi), which was established under Mr Gove's predecessor Chris Grayling in 2013.

Mr Gove closed it down amid criticism that it was selling prison expertise to countries with poor human rights records.

The MoJ had previously insisted that JSi's work was focused on trying to improve human rights standards in the countries' jails through training and prison design.

'Media spotlight'

In the case of Mr Andree, Downing Street said Mr Cameron was personally intervening by writing to the Saudi government.

Mr Andree, who has lived in the Middle East for 25 years, was arrested in 2014 after being caught with homemade wine by Saudi religious police.

However, BBC security correspondent Frank Gardner said both Saudi and UK government officials have told him there was never any question of Mr Andree being flogged.

"The Saudis privately gave the Foreign Office assurances he was not going to be flogged, but delays in Saudi bureaucracy meant that his release papers have been held up before they reached the prison and the family grew increasingly worried," he said.

"The media spotlight now means that his release will either be speeded up or possibly, out of pique, get put back further."