President Trump said Thursday that he had tried to stop the release of John Walker Lindh, known widely as the “American Taliban,” from an Indiana prison, but that there was no legal way to do so.

Mr. Lindh was freed on probation after serving 17 years of a 20-year sentence for providing support to the Taliban, according to the Federal Bureau of Prisons. He was captured during the invasion of Afghanistan in the fall of 2001 and returned to the United States the next year.

Mr. Trump said at an afternoon news conference that he was unhappy about Mr. Lindh’s release, but that the “best lawyers in our country that work for government” had told him there was no way to legally stop it.

“The lawyers have gone through it with a fine tooth comb,” Mr. Trump said. “If there was a way to break that, I would have broken it in two seconds.”