Presiding judge Muhammad Mustapha Umar of the Upper Sharia court said on Wednesday that the lower Sharia (Islamic law) court was wrong in sentencing Hajara Ibrahim, 18, to death by stoning last October.
"This court observes the following faults in the lower court judgement. Firstly, the judge was wrong in sentencing Hajara to 100 lashes and death by stoning, all at the same time," he said.
"Secondly, Dauda Sani was charged to court for having an affair with Hajara which he denied. Therefore, the lower court should have dismissed the case and sentenced Hajara's father who was the plaintiff to 80 lashes for slander."
The judge at the court in Dass, in the northern Bauchi state, said the lower court also erred by not giving Hajara the chance to defend herself.
"Any judgement passed without chance of defence is null and void. Based on these reasons, this court hereby nullifies the lower court judgement and discharges and acquits Hajara Ibrahim," he added.
Judge Umar said anybody who is not satisfied with the ruling can file an appeal at the Sharia court of appeal.
Hajara's lawyer, Abd al-Qadir Sulaiman, had argued that the October ruling was invalid because Hajara had not consummated her marriage before sleeping with her boyfriend and conceiving a child.
Nigeria's Muslim north has largely
opted for Islamic law
Following the ruling Hajara Ibrahim said she was happy and thanked those who assisted her.
"My main worry now is my health and that of my child. I hope for a safe delivery," she said.
The 18-year old said she has forgiven her boyfriend for denying he had an affair with her. "I have left him to his conscience," she said.
Since 1999, 12 states across the mainly Muslim north of the country have begun reintroducing Sharia principles into their penal codes, including punishments such as flogging, amputation and stoning.
No stonings have yet been carried out, but several men and women around the region have been convicted of a variety of sexual crimes - adultery, rape or sodomy - and are awaiting news of their appeals.
"Any judgement passed without chance of defence is null and void. Based on these reasons, this court hereby nullifies the lower court judgement and discharges and acquits Hajara Ibrahim"
Judge Muhammad Mustapha Umar,
Upper Sharia Court,
Bauchi state, Nigeria
Proponents of Islamic law say the punishments are a small part of a system which guarantees law and order and the wellbeing of society.
However, human-rights groups have denounced the punishments as barbaric.