A panel of five judges at the Sharia Appeal Court in Katsina state ruled in favour of Amina Lawal, 31, at her appeal hearing on Thursday.
"We acquit her and discharge her for the offence she was convicted for," said judge Ibrahim Mai-Unguwa.
A cry of "Allahu Akbar" (God is great) went up in the crowded courtroom and Lawal's baby daughter Wasila cried out briefly as the majority ruling was read out.
Mai-Unguwa said it had been wrong for the lower appeal court to have refused to allow Lawal to retract the confession she made in her initial trial in March last year.
Then, judges in the small country town of Bakori sentenced Lawal to be stoned to death for adultery after the twice-divorced mother-of-two gave birth out of wedlock.
Lawal's defence team appealed the sentence, arguing at the first appeal hearing that her conviction had been unfair and that she had gone back on the confession she made a few months earlier.
The young mother had had no legal representation, the defence argued, and did not understand what she had been charged with.
The defence also argued that if Lawal did have sexual relations after her second divorce, this must have taken place before Katsina State formally adopted the Sharia penal code in June 2001.
Sharia judges said Lawal should
not have been prosecuted after
withdrawing her confession
"Giving birth is not a crime, even if adultery is," lawyer Musa Aliyu Yawuri said then.
Meanwhile, only moments after Lawal was acquitted officials announced a Nigerian man had been sentenced to death by stoning for sodomy.
The conviction of 20-year-old Jibrin Babaji for sleeping with three boys was made on Tuesday by a Sharia court in the northern Bauchi State.
A spokesman for the court, Bala Ahmed, said Babaji had been sentenced after having confessed to sexually molesting the minors at different times over the past year.
Babaji, who remained sober and remorseful throughout the ordeal, vowed to appeal the ruling, he added.
The boys, whose ages were not given, said they had been lured into having sex with the man with an offer of 50 naira (about 30 US cents), according to the court official.
They were each sentenced to receive 50 lashes of the cane for accepting the money.
Twelve mainly Muslim states have reintroduced Sharia since the country's return to civilian rule in 1999, in spite of opposition from the federal government and Christians.
Sharia bans adultery, fornication, stealing, gambling, drunkenness, among other acts.
However, Nigerian Islamic groups, who welcomed the Lawal verdict, say that the Sharia has been imperfectly implemented in northern Nigeria.