A 13-year-old boy who was handed a decade-long jail sentence for blasphemy last year will now walk free.
He was convicted by an Islamic court 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.
The authorities in Kano state appear unhappy with the dismissal of the case against the minor. The state Attorney-General Musa Lawan told the BBC that they would consider appealing against the ruling.
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.
Kano’s attorney-general hailed the ruling as a “victory for Kano people”.
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, 22, 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 Reuters news agency.
The teenager’s parents disassociated themselves from him due to the shame caused by the case, according to Mr Alapinni.
Sharia controversy lingers
Analysis by Is’haq Khalid, BBC bilingual reporter, Abuja
The acquittal of the teenage boy will come as a relief to human rights campaigners. But in Kano state, where the majority of the population are Muslims, there is a strong support for Sharia and little public discussion of the boy’s case.
Instead, people are more passionate about Yahaya Sharif-Aminu’s case. The latest ruling may not go down well with some residents who have been calling for his execution, while others will keenly follow the retrial if it starts.
Across the country, the latest judgements have generated mixed reaction and once again raised the lingering controversy over the implementation of Sharia in some Nigerian states.
Kano is among around a dozen states in northern Nigeria that practise the Sharia legal system alongside the country’s secular laws. Only Muslims can be tried in Sharia courts.