A 13-year-old boy who was handed a decade-long jail sentence for blasphemy last year will now walk free.
An Islamic court convicted by in August for making uncomplimentary remarks about God during an argument with a friend in northern Kano state.
But a secular appeals court overturned the sentencing on Thursday, saying the child was a minor.
Last year’s ruling by a Sharia court sparked international condemnation.
The UN children’s agency, Unicef, said it “negate[d] all core underlying principles of child rights and child justice that Nigeria – and by implication, Kano state – has signed on to”.
In September 120 volunteers, led by the director of the Auschwitz memorial in Poland, offered to serve part of the original 10-year jail sentence given to the boy.
It is not clear whether the Kano state authorities that initially brought the case will further appeal.
Kano is one of 12 Nigerian states practising the Sharia legal system alongside the country’s secular laws.
Muslims form the majority in northern Nigeria, where only Muslims can be tried in the Sharia courts.
The appeals court also ordered a retrial in another blasphemy case, involving a singer sentenced to death by the Sharia court for using lyrics deemed blasphemous against the Prophet Muhammad.
According to the lawyer representing both defendants, “their lives will never be the same again”.
Kola Alapinni said it would not be safe for the teenager to remain in Kano, while singer Yahaya Sharif-Aminu was likely to remain in custody until his retrial.
Protesters in Kano destroyed Mr Sharif-Aminu’s home last year, forcing his family to flee, reports the Reuters news agency.
The teenager’s parents disassociated themselves from him due to the shame caused by the case, according to Mr Alapinni.