The High Court has ordered the immediate release of the man known as Mr A who was serving a three-year sentence for the unlawful carnal knowledge of a 12-year-old girl.
Ms Justice Mary Laffoy said his detention had been rendered unlawful by last week's Supreme Court decision striking down the law on statutory rape.
The court also found that it did not have the jurisdiction to continue to hold the 41-year-old in custody to allow the State to go to the Supreme Court.
Mr A had claimed that he was being held in prison on a warrant which is based on a non-existent law.
The man was 38 at the time of the offence and was nearly two years into a three-year sentence.
Senior counsel Gerard Hogan said during legal submissions yesterday that it would be appalling if those who pleaded guilty to very serious offences involving pre-teen children were to get a windfall bonus from the Supreme Court.