An Iranian asylum seeker who raped a teenage girl has been spared deportation even though a judge believed his conversion to Christianity was a deliberate ploy to cheat the justice system.

The 38-year-old man, who arrived in the UK in 2006, was sentenced to five years' imprisonment after raping the 17-year-old in 2012.

But after his release from prison, a judge ruled that his claim to be Christian meant his deportation to Iran would be a breach of his human rights.

The judge, who acknowledged that the man's religious conversion was part of a ploy to avoid deportation, ruled that his 850 twitter posts quoting the Bible and Christian theology placed him at risk of persecution if he was sent back to Iran.

The judge said: 'In all the circumstances, I am satisfied that the appellant has established that there is a real risk that on his return he would be questioned about the details of his asylum claim and that that questioning would reveal that he has posted on Twitter......(and) interrogation would involve a real risk of ill-treatment amounting to a breach of article 3.'

The immigration tribunal judge said it didn't matter that his conversion to Christianity was not genuine because the Iranian authorities would still be able to read his pro-Christian tweets.

The man, who can only be referred to as AM, entered the United Kingdom on 15 January 2006 and lodged an asylum application the same day.

This was rejected on 3 February 2006 and his rights of appeal against that refusal were exhausted on 2 June 2006.

But on 1 April 2008, he applied for a Residence Card on the basis that his wife was a member state of the European Economic Area. This was granted in December 2009 for five years, expiring 2014.

On 5 August 2013 he was found guilty of the rape of a 17-year old girl on 28 September 2012, and sentenced to five years imprisonment, with an order of indefinite registration on the sex offenders register.

He was released from prison on 18 August 2015 when the then Home Secretary, Theresa May, ordered his deportation on grounds that he represented 'a genuine, present and sufficiently serious threat to the public.'

But he appealed that decision claiming to be a Christian who would be persecuted if he was returned to Iran.

The Home Office argued that none of the tweets were anti-Islamic but the judge disagreed with the Secretary of State's characterisation of them as 'simply quotations from the Bible.' There were quotations from the New Testament and religious images, and retweets which he said were likely to find disfavour with the Iranian authorities. One of the tweets read, 'people in the Middle East are still finding Jesus despite it all.'

At one point AM's Twitter account had more than 5,000 followers and 86,000 likes. The Home Office has spent tens of thousands of pounds fighting the case and lodged an appeal with the Court of Appeal, arguing that AM's conviction meant he should be deported on grounds of public policy.

This month the Court of Appeal ruled that the whole case should be reheard.

Lord Justice Simon said: 'In these circumstances, I would allow the appeal; and remit the case to the Upper Tribunal for AM's appeal to be considered in the light of this judgment. I would also add that directions should be sought as to the admission of any evidence and further specific submissions on the Twitter issue.'

A Home Office spokesperson said it would be inappropriate to comment on ongoing legal proceedings.