An Iranian Christian pastor who refused to renounce his faith after being sentenced to death for apostasy has been released from prison.

Youcef Nadarkhani, 35, was released from prison on Saturday and reunited with his family after a court in the northern city of Rasht, the capital of Iran's Gilan province, acquitted him of apostasy, which carried the death sentence under Iran's Sharia law.

"Nadarkhani was acquitted of apostasy but instead charged with acting against the national security and therefore sentenced to three years in jail," a reliable source in Rasht, who asked not to be named for fear of government reprisal, told the Guardian. "But because he had already served three years in prison, he was allowed to go home."

It is believed Nadarkhani's lawyer argued in court that Iran was a signatory to international treaties requiring it to respect freedom of religion.

Nadarkhani was arrested in October 2009 for converting at the age of 19 to Christianity from Islam, his parent's religion. Although he insisted he was never a practising Muslim, Iran considers the religion of a child to be that of his father. Those who convert to other religions risk arrest or even execution for apostasy.

In 2010, Nadarkhani was sentenced to death after being found guilty of apostasy, a conviction upheld by a supreme court in 2011. Iran's penal code does not have a definitive ruling for apostasy and the judge often refers to the Sharia law for such cases.

According to Amnesty International, Nadarkhani was arrested because he "protested against his child being given mandatory lessons on Islam in school".

Nadarkhani was reportedly told during his previous court hearings that he could be freed if he renounced Christianity, which he repeatedly refused. "I am resolute in my faith and Christianity and have no wish to recant," he told a judge, according to Amnesty.

Nadarkhani's case attracted international condemnation. Amnesty described him as a prisoner of conscience who was "being held solely on the basis of his religious beliefs".

In April, another pastor, Farshid Fathi, 33, became the latest victim of state persecution of Christian converts after being sentenced to six years in prison by a revolutionary court, Iran Christian News Agency reported.

Other religious minorities in Iran have been facing restrictions, including Bahá'ís. Seven leaders of the Bahá'í community are serving 20-year jail sentences. Bahá'ís in Iran are deprived of rights, such as education or owning businesses, and are often persecuted for their beliefs.