For an example of how the U.S. government can work at cross-purposes in dealing with terrorism, take a look at the failed effort to release Afghan prisoners from Guantanamo Bay. It shows how an incorrect analysis — that the Taliban and al-Qaeda pose the same threat — can lead to a cascade of bad policy that has undermined U.S. interests.

The false premise that the Taliban and al-Qaeda were equally dangerous was enacted into law by Congress in 2010. This confusion complicated the release of five Taliban prisoners from Gitmo during reconciliation talks in 2011; it confounded the Afghan government’s efforts to seek release of eight other Afghans; and it helped fuel a hunger strike described by one prisoner in a recent New York Times op-ed headlined “Gitmo Is Killing Me.”

The bottom line: The Taliban have gained a propaganda advantage; and President Obama’s desire to close Guantanamo has been sabotaged by domestic political pressure. All this despite CIA assessments that the release of the Afghan prisoners wouldn’t pose a high security risk.

The story begins with the U.S. military campaign in October 2001 to topple the Taliban government that had provided safe haven for al-Qaeda. Many Afghans were taken prisoner and some were sent to Guantanamo Bay, Cuba, including senior Taliban officers and other Afghans who were deemed a threat.

The premise for treating the Taliban and al-Qaeda as equivalent enemies was summarized in Bob Woodward’s book “Bush at War,” which indirectly quotes then-CIA Director George Tenet: “We have to deny al Qaeda sanctuary, Tenet said. Tell the Taliban we’re finished with them. The Taliban and al Qaeda were really the same.” Tenet says he didn’t view the two as “equivalent” threats, but that logic has prevailed ever since, despite skepticism from some CIA analysts as they examined the individual cases.

The United States began exploring the release of Taliban prisoners after Obama took office in 2009. Obama had announced that he wanted to close the prison, and his new special representative for Afghanistan, Richard Holbrooke, was trying to open bargaining for a political settlement. The Pentagon, backed by conservatives in Congress, opposed any prisoner release that would put Taliban fighters back on the battlefield.

Quiet conversations started in April 2009, when Barnett Rubin, an Afghan expert at New York University who would soon join Holbrooke’s team, met with Abdul Salam Zaeef in Kabul. Zaeef, a former Taliban ambassador who had been released from Gitmo in 2005, named six prisoners the Taliban hoped would be freed. Support for the idea came from BurhanuddinRabbani, a former Afghan president who was heading reconciliation efforts for President Hamid Karzai. He wrote the United States a letter in early 2011 asking for the release of one of the six, Khairullah Khairkhwa.

A breakthrough seemed near in 2011. Holbrooke’s successor, Marc Grossman, met secretly with Taliban representative Mohammed Tayeb al-Agha. They worked out a deal in which the United States would release five Taliban prisoners and send them to Qatar. The Taliban, in return, would condemn international terrorism and release U.S. Army Sgt. Bowe Bergdahl, whom the militants had been holding since 2009.

But the deal fell through in December when Karzai objected, protesting that he hadn’t been involved. He relented the next month after sending his national security adviser Ibrahim Spinzada to Gitmo to talk to the prisoners. But by then the Taliban had cooled, and it suspended the talks in March 2012.

What made this exercise so frustrating was that the CIA had studied the five Taliban detainees who were slated for release and concluded that this would have no net effect on the military situation, even if they broke their pledges and left Qatar. Evidence suggested that although the five had fought with the Taliban, they had no role in supporting al-Qaeda’s plots and had quickly surrendered after the U.S. offensive started.

The last chapter of this story is the most perplexing. At the NATO summit in Chicago last May, Karzai asked Obama to release eight other Afghans. The CIA examined these dossiers, too, and found four of them to be low risk and four to be medium risk. But because of the 2010 congressional requirements governing any release from Gitmo, the United States made elaborate demands for how the Afghans would be monitored back home. Karzai’s government never bothered to answer.

The Obama administration still says it wants a political settlement in Afghanistan, but progress has stalled. As for the Afghan prisoners, they remain among the 166 detainees at Guantanamo, of whom 52 are now on a hunger strike protesting their treatment and 15 are being force-fed.

Read more from David Ignatius’s archive, follow him on Twitter or subscribe to his updates on Facebook.