TOPEKA, Kan. — A Kansas man whose lawyer says he is mentally ill pleaded guilty Wednesday in connection with a plot to plant a bomb outside an Army post, acknowledging that he wanted to aid the Islamic State of Iraq and Syria (ISIS).

John T. Booker Jr. of Topeka admitted in court to trying to set off what he thought was a 1,000-pound bomb in a van outside Fort Riley, about 60 miles west of Topeka. He signed a plea agreement with prosecutors that recommends he spend 30 years in prison.

Booker, 21, was arrested outside the post in April 2015 as he was trying to arm what he believed was the bomb. He had been plotting the bombing with two contacts who actually were confidential FBI sources.

“If this defendant had succeeded, American soldiers would have died,” U.S. Attorney Barry Grissom said in a news release, CBS affiliate WIBW reported. “The investigators and the attorneys who worked on this case were our line of defense against terrorism. They kept us safe.”

During the hearing, defense attorney Kirk Redmond told U.S. District Judge Carlos Murguia that Booker has been diagnosed with bipolar disorder, which is characterized by mood swings that can affect functioning. Redmond said Booker is taking medication for the disorder, which Booker confirmed in court.

Neither Redmond nor Booker said whether the disorder was a factor in Booker’s actions. A Muslim cleric who counseled Booker before his arrest said at the time that Booker was acting strangely in the days leading up to it.

Kansas man accused in failed Army base bomb plot sentenced

Read Next: Kansas man accused in failed Army base bomb plot sentenced

Booker pleaded guilty to one count of attempting to use a weapon of mass destruction and one count of attempting to destroy government property with an explosive device. The plea agreement recommended a sentence of 30 years on the first charge and 20 years on the second, to be served at the same time. A conviction on the weapons-of-mass-destruction charge could have led to life in prison.

As part of the plea deal, prosecutors dropped a charge of attempting to provide material support to ISIS.

Booker initially pleaded not guilty to all three charges, but notified Murguia in December that he wanted to change his pleas. His hearing Wednesday was scheduled to allow him to do that.

Murguia has not yet scheduled a sentencing hearing. He advised Booker that in any criminal case, the judge does not have to follow the recommendations in plea agreements.

“There’s no limit on the information the court could consider,” Murguia said.

Still, when the judge asked whether Booker still wanted to plead guilty, he answered, “Yes,” in a calm voice.

Booker acknowledged in court that he told one of the FBI informants that he wanted to kill Americans and engage in violent jihad on behalf of ISIS.

Read more at CBS News