RALEIGH, N.C. (AP) — A mentally ill North Carolina man who the government fought for years to prosecute as an example to others considering joining militant fighters in Syria pleaded guilty Wednesday to providing material support to a terrorist group.

Basit Sheikh's plea bargain disclosed in a Raleigh federal courtroom would see the 34-year-old released early next year, but by late 2020. His sentencing by U.S. District Judge Terrence Boyle is scheduled for early October.

The guilty plea also could cause the Pakistan native with permanent, legal residency in the U.S. to be kicked out of the country, according to the plea agreement.

Sheikh, 34, said little beyond acknowledging he felt better and to agree to elements of the plea bargain.

He was an early arrest in the FBI's effort to find and capture U.S. residents thinking of joining terrorist groups before they could go to Syria, and perhaps return home battle-hardened. Sheikh has spent almost five years in custody since his November 2013 arrest at Raleigh's airport on his way to the Middle East.

Sheikh's online attraction to the group Jabhat al-Nusra, which the U.S. government declared a terrorist organization, was a secret to his family, his father said outside the courtroom.

"To the best of my knowledge he did not have any connection to these" groups, Javed Sheikh said, adding he wanted his son to return to the family's suburban Cary home after his release from prison. "I raised him not to be like this."

Sheikh was attracted in early 2013 to an FBI-run Facebook page that posed as a forum for militant Muslim views.

Sheikh was drawn into the idea of fighting against Syrian President Bashar Assad's troops through his written, online discussions with an FBI agent or confidential informant who posed as a female nurse in Syria. Sheikh's communications with the FBI operative became personal and even romantic before Sheikh was introduced to another FBI contact described as able to introduce him to al-Qaida-linked fighters.

Sheikh said he hadn't planned on joining the fighting, but instead wanted to help refugees and marry the "nurse."

Sheikh was forcibly medicated for schizophrenia by government doctors so he could be competent to defend himself against prosecution. Prosecuting and convicting Sheikh was important in order to deter other would-be American radicals, prosecutors have said in court.

There were about 110 forcible medication cases considered by federal courts nationwide in the 13 years after a 2003 U.S. Supreme Court ruling that restricted involuntary medication to certain serious criminal cases, according to research by Georgetown University law professor Susan McMahon. Courts approved the motions almost two-thirds of the time, McMahon said.

____

Follow Emery P. Dalesio on Twitter at http://twitter.com/emerydalesio. His work can be found at https://apnews.com/search/emery%20dalesio.