An Islamic Court sitting in Bauchi on Thursday found Mr Mubarak Ibrahim guilty of committing homosexual offences and ordered that he receives 20 lashes.
The court however tempered justice with mercy as Mr Ibrahim was given 20 lashes. Under Islamic law, courts can punish homosexual acts by stoning to death.
But the judge said he took into account that the Muslim man, Mubarak Ibrahim, 20, carried out the acts seven years ago, and had stopped the practice.
In Nigeria, homosexual acts are illegal under both Islamic and secular law and restrictions have been tightened.
President Goodluck Jonathan signed into law a bill which bans same-sex marriages, gay groups and shows of same-sex public affection.
Along with Mr Ibrahim, 11 other Muslims and a Christian man were arrested last month accused by the authorities of being homosexuals.
He was also ordered to pay a fine of about N4, 500.
Mr Ibrahim told the BBC he was relieved that Judge Nuhu Muhammad had been lenient on him and had not sentenced him to death.
The fate of the nine other men arrested on the same charge is unclear but on Wednesday the Sharia Commission in Bauchi said the Christian would be tried by a “conventional court”, not an Islamic court.