TOPEKA, Kan. -- A man charged Friday with plotting a suicide bomb attack on a U.S. military base to help the Islamic State group was mentally ill and was acting strangely only days before his arrest, according to a Muslim cleric who said he was counselling him at the request of the FBI.

John T. Booker Jr., of Topeka, is accused of planning a suicide attack at Fort Riley, about 70 miles (112 kilometres) west of Topeka. Prosecutors allege he told a Federal Bureau of Investigation informant he wanted to kill Americans and engage in violent jihad on behalf of the terrorist group, and said he believed such an attack was justified because the Qur'an "says to kill your enemies wherever they are," according to a criminal complaint.

Authorities arrested Booker on Friday as he was trying to arm what he thought was a 1,000 pound (455 kilogram) bomb outside the Army post. The criminal complaint filed in federal court in Topeka charges him with three crimes, including attempting to use a weapon of mass destruction.

The top federal prosecutor for Kansas also charged another Topeka man, Alexander E. Blair, 28, with failing to report Booker's plans to authorities. The complaint alleges that Blair and Booker shared some "extremist views" and that Blair loaned Booker money to rent space to build and store a bomb.

Imam Omar Hazim of the Islamic Center of Topeka told The Associated Press that two FBI agents brought Booker to him early in 2014 for counselling, hoping to turn the young man away from radical beliefs. Hazim said the agents told him that Booker suffered from bipolar disorder, characterized by unusual mood swings that can affect functioning.

Hazim said he expressed concerns to the FBI about allowing him to move freely in the community at their first encounter.

Hazim said he later heard that two others were involved in a bombing plot with Booker. He said the FBI told him they were undercover FBI agents and that the sting was arranged to get Booker, "off the streets."

"I think the two FBI agents set him up, because they felt at that point someone else might have done the same thing and put a real bomb in his hands," Hazim said.

He said he has come to the conclusion that the sting was the right thing to do. He said Booker admitted to him on Tuesday that he had stopped taking his medication because he didn't like the way it made him feel and it was expensive.

A spokesman for the U.S. attorney's office in Kansas declined to comment on Hazim's comments.

The soft-spoken Booker made his first court appearance Friday in U.S. District Court in Topeka, answering basic questions and correcting the spelling of his alias, Muhammad Abdullah Hassan. Booker was ordered to remain jailed. A grand jury is expected to consider the case next week.

Booker's public defender, Kirk Redmond, declined comment following the hearing.

Booker was recruited to join the Army in February 2014, but came to the attention of federal investigators after posting a Facebook message on March 19, 2014, that read: "Getting ready to be killed in jihad is a HUGE adrenaline rush! I am so nervous. NOT because I'm scared to die but I am eager to meet my lord." His military enlistment was terminated days later, according to the Army.

His father, John T. Booker Sr., told the AP that his son moved out about two years ago after graduating from high school. The elder Booker, an Army veteran who served in Desert Storm, said he and his son had talked only about four times in the past year.

He said he is Methodist and his wife is Catholic, and that he knew nothing about the religious beliefs of his son.

------

Associated Press writers Bill Draper and Heather Hollingsworth in Kansas City, Missouri, and Roxana Hegeman in Wichita contributed to this report.