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-Qaieda's North African branch, known as al-Qaeda in the Islamic Maghreb, officials said.

The Mauritanian appeals court decided 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, saying he came to Mauritania only to learn Arabic and study the Qur'an.

Yoon reportedly travelled to the region with two other Canadians who were implicated in a terror attack on a 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.

Responsibility for 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, Yoon claimed he was tortured in detention. The torture led him to sign a confession that has been used against him at every stage of the case, Alex Neve, secretary general of Amnesty International Canada, told The Canadian Press last month.

In an interview Monday, Neve said he couldn't say whether Amnesty's recent report on the issue had any influence on Sunday's decision.

"I think it was obvious to the Mauritanian authorities that there was concern about this case and it was being watched closely," Neve said.

He said Amnesty has no way of verifying the claims linking Yoon to al-Qaeda. "But it was very clear to us that there are serious human rights concerns, including torture."

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 Qur'an, first arriving in Morocco. They later travelled to Mauritania, studying at a school in Nouakchott before relocating to a school in Naim, a village 100 kilometres away.

Yoon has said that he didn't know how Medlej and Katsiroubas had become linked with militants. He said he heard about the gas plant attack while in prison, and that it was "news" to him at that point.

Neve said he didn't know when Yoon would be permitted to leave the country, but that he was anxious to see his family back in Canada.

"His most immediate wish was to be back with his family and recover and spend time with them."

The Canadian Security Intelligence Service declined to comment on Yoon's case Monday. Public Safety Department spokesman Jean Paul Duval also had little to say.

"I can say that security agencies take appropriate steps to keep Canadians safe," he said. "We are not going to comment any further on this case."

The Mounties were also tight-lipped.

"We are aware of media reports indicating that a Canadian jailed in Mauritania is to be freed," said Sgt. Greg Cox, an RCMP spokesman. "The RCMP will not comment further."

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," he told them. "Simply asserting those rights is what unleashed the torture. They were furious with me."

He told Amnesty he was beaten and hit with sticks of wood until he lost consciousness. Amnesty also reported he said later that his hands and feet were tied behind his back, and the beating resumed after he was laid down on his stomach.

Amnesty said 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-Qaeda. 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," Neve said. "Every official and every judge who has reviewed his case has relied on it."

Neve 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.

Associated Press writers Rukmini Callimachi and Robbie Corey-Boulet contributed to this report from Dakar, Senegal.