NOUAKCHOTT, Mauritania — A 24-year-old Canadian man is to be released from a Mauritanian jail after being sentenced to 18 months in prison and a $2,000 fine for alleged ties to al-Qaida's North African branch, known as al-Qaida in the Islamic Maghreb, officials said.

The Mauritanian appeals court decided on Sunday to free Canadian national Aaron Yoon, the same day as his sentencing, because he has already been imprisoned for the duration of his sentence, prosecutor Ahmed Ould Abdalla told The Associated Press.

"The court has decided to free the Canadian, Yoon, because he has already served his time. He will be expelled from Mauritania immediately," said Abdalla. Yoon was first arrested in December of 2011.

Prosecutors had sought a 10-year sentence for Yoon due to what they claimed was his "link to dangerous terrorist activity and his role in the recruitment of jihadists." Yoon has denied that he had any ties to terrorism, claiming he came to Mauritania only to learn Arabic and study the Quran.

Yoon reportedly travelled to the region with two other Canadians who were implicated in a terror attack on a BP-operated natural gas plant in southeastern Algeria earlier this year, one of the largest attacks in recent memory. It ended with the deaths of 37 hostages including American, French, Irish and Japanese nationals. The attack was claimed by Moktar Belmoktar, a former commander of al-Qaida in the Islamic Maghreb, who split off from the al-Qaida chapter late last year in order to create his own group.

Belmoktar had previously carried out several attacks in Mauritania, which has served as a fertile recruiting ground for the jihadists, who now have several Mauritanians in their ranks.

In April, Canadian police confirmed the identities of two Canadians who were killed at the Ain Amenas gas plant in southeastern Algeria: Ali Medlej and Xristos Katsiroubas. Algeria's government has said they were involved in the attack as hostage takers.

During several visits by Amnesty International Canada in June and July 2012, Yoon claimed he was tortured in detention, leading him to sign a confession that has been used against him at every stage of the case, according to a statement issued last month by Alex Neve, secretary general of Amnesty International Canada.

The statement said Yoon attended high school in Ontario with Medlej and Katsiroubas. Yoon told Amnesty he left Canada with the two men in May 2011 to study Arabic and the Quran, first arriving in Morocco. They later traveled to Mauritania, studying at a school in Nouakchott before relocating to a school in Naim, a village 100 kilometers (62 miles) away.

Yoon told Amnesty that he was beaten in police custody soon after being detained in December 2011. "I couldn't answer many of their questions without a translator anyway as my Arabic was still pretty basic at that time," Yoon told Amnesty. "Simply asserting those rights is what unleashed the torture. They were furious with me."

He said he was beaten and hit with sticks of wood until he lost consciousness. Later, his hands and feet were tied behind his back, and the beating resumed after he was laid down on his stomach. It was after this second round of torture that he agreed to sign the confession saying he had planned to travel to Mali to join up with al-Qaida. Amnesty said the confession was written in Arabic and was never read or translated for him.

"The statement he signed has followed him everywhere since," Nave said. "Every official and every judge who has reviewed his case has relied on it."

Nave said there had been no witnesses or other evidence presented in court against Yoon. While Yoon was given a court-appointed lawyer for one appearance, he said the lawyer "did not actively intervene in the proceedings to defend him."

Amnesty said it could make no judgment on the allegations against Yoon, but noted that Yoon's account of being tortured was consistent with many other cases documented by the rights group.