Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

A soldier stationed in Kansas accused of talking about a terrorist attack in the United States pleaded guilty Monday to distributing instructions for making explosive devices over social media, federal prosecutors said.

Pfc. Jarrett William Smith, 24, was arrested in September after he was accused of discussing killing members of the far-left Antifa movement and attacking a major news outlet with a vehicle bomb.

Smith pleaded guilty Monday to two counts of distributing information related to explosives, destructive devices and weapons of mass destruction, the U.S. Attorney's Office for the District of Kansas said in a statement, and he faces up to 20 years in prison.

Sentencing is scheduled for May 18.

Prosecutors said that on Sept. 20, Smith sent a person — who was actually someone working undercover for the FBI — instructions for making an improvised explosive device. He was also alleged to have provided a recipe to create improvised napalm.

Smith formally changed his plea Monday during a half-hour hearing before U.S. District Judge Daniel Crabtree.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

He was asked by the judge, "Did you provide this information with the intent that the person would use it?" and Smith replied, "Yes," according to The Associated Press.

Smith joined the Army in June 2017 and served as an infantry soldier, and he was trained in combat and tactical operation, prosecutors said. He was transferred to Fort Riley on July 8. He was listed as having been born in Conway, South Carolina, according to Army records.

In a chat in September on the cloud-based instant messaging service Telegram, an undercover agent said he wanted to target a "liberal Texas mayor" for bombing and asked Smith whether he had any other suggestions, according to an FBI affidavit filed in the case.

"Outside of Beto?" Smith is alleged to have responded, apparently referring to Democratic former Rep. Beto O'Rourke, who was running for president at the time. "I don't know enough people that would be relevant enough to cause a change if they died."

Download the NBC News app for breaking news

In August, Smith engaged in a conversation with a confidential source in an online chat group and "discussed a plan of conducting an attack within the United States," saying "he was looking for more 'radicals' like himself," according to the affidavit.

Before he talked about his alleged desire to target news stations, Antifa and O'Rourke, Smith's fascination was with a far-right Ukrainian paramilitary group, according to the affidavit.

Federal prosecutors said Smith spoke to others on social media about wanting to travel to Ukraine to fight with a violent, far-right military group, which was identified in court documents as the paramilitary group Azov Battalion.

Federal public defenders listed in court documents as representing Smith did not immediately return emailed requests for comment Monday night.

Smith's defense attorney, Rich Federico, has argued in court that Smith was being prosecuted for forwarding information available to anyone with "Google and 10 minutes" and that Smith was having a difficult transition to Army life and was "essentially a chatroom troll," according to the AP.

Court documents say that Smith admitted that he knows how to make improvised explosive devices and that "in online chat rooms he routinely provides instruction on building explosive devices." Smith is alleged to have said he did so to cause "chaos."

He is also alleged to have said in a pre-arrest interview that he gives the information for the "glory" of "his religion of anti-kosmik Satanism." The detention order does not elaborate.