BERLIN - By January of 2004, when German citizen Khaleed al-Masri arrived at the Central Intelligence Agency’s secret prison in Afghanistan, agency officials were pretty sure he wasn’t a terrorist. They also knew he didn’t know any terrorists, or much about anything in the world of international terror.

In short, they suspected they’d nabbed the wrong man.

Still, the agency continued to imprison and interrogate him, according to a recently released internal CIA report on al-Masri’s arrest. The report claims that al-Masri suffered no physical abuse during his wrongful imprisonment, though it acknowledges that for months he was kept in a “small cell with some clothing, bedding and a bucket for his waste.” Al-Masri says he was tortured, specifically that a medical examination against his will constituted sodomy.

The embarrassing, and horrifying, case of al-Masri is hardly new. It has been known for a decade as a colossal example of CIA error in the agency’s pursuit of terrorists during the administration of President George W. Bush.

But the recently released internal report makes it clear that the CIA’s failures in the al-Masri case were even more outrageous than previous accounts have suggested.

The report is heavily redacted - whole pages are blank - and the names of those involved have been removed. But enough is there to give a good understanding of what happened and what went wrong.

Adding to the sense of injustice: Even though the agency realized early on that al-Masri was the wrong man, it couldn’t figure out how to release him without having to acknowledge its mistake. The agency eventually dumped him unceremoniously in Albania and essentially pretended his arrest and detention had never happened.

The release of the report, which is 90 pages long and was written in July 2007, came in June after a Freedom of Information Act suit by the American Civil Liberties Union, which is representing al-Masri in his decadelong attempt to get an official apology from the United States.

Assembled by the CIA’s inspector general, the report provides the clearest official view to date into the dark, murky world of the Bush administration’s anti-terror rendition program. Beyond snatching an innocent man and holding him for five months, the report highlights a shocking lack of professionalism at America’s top spy agency. The Hollywood cliche of deeply devoted patriots doing their best to protect the United States appears, in this case, to have been replaced by a classic bureaucratic mess and individuals most intent on protecting their own careers.

The report notes that al-Masri was “questioned in English, which he spoke only poorly.”

None of the Americans involved in al-Masri’s detention has been held to account, notes al-Masri’s attorney, Jamil Dakwar, the director of the American Civil Liberties Union’s Human Rights Program. Indeed, the two men most responsible for the errors were promoted. Meanwhile, Dakwar said, al-Masri is haunted to this day by the psychological torture inflicted by his detention in the CIA’s secret Afghan holding center and by the stigma of having been snatched in a CIA anti-terror investigation.

The tale has important lessons for the country, where one of the two leading presidential candidates, Donald Trump, has promised to reinstate the use of torture against terrorism suspects and the Obama administration has declined to punish anyone for the excesses of the Bush-era rendition program.

“When you start a program shrouded in secrecy that pushes the line on human rights, nobody should be surprised that we see this result,” Dakwar said. He added that the presidential authority given for the program under which al-Masri was nabbed required the CIA “to satisfy a very low bar of proof. In this case, they admit they knew at the time that they didn’t reach even that bar.”

In the case of al-Masri, the inspector general’s report is sweeping in its condemnation of the failures that took place throughout the agency’s hierarchy, blaming the mishandling of his arrest and detention on “a series of breakdowns in tradecraft, process, management and oversight.”

The report lists the failures: “The lack of rigor in justifying action against an individual suspected of terrorist connections; the lack of understanding of the legal requirements of detention and rendition; the lack of guidance provided to officers making critical operations decisions with significant international implications; and the lack of management oversight.”

It offered a particularly harsh judgment of Alec Station, the CIA unit charged with tracking down Osama bin Laden after the Sept. 11, 2001, terror attacks in the United States.

“ALEC Station exaggerated the nature of the data it possessed linking al Masri to terrorism. After the decision had been made to repatriate al Masri, implementation was marked by delay and bureaucratic infighting,” the report says.

The report notes that all agency attorneys interviewed agreed that al-Masri did not meet the legal standard for rendition and detention, which required that a suspect be deemed a threat. In al-Masri’s case, it was thought only that he “knows key information that could assist in the capture of other al Qaida operatives.”

Despite the fact that the CIA was unable to find any evidence tying al-Masri to an al-Qaida operative in Sudan, which had been the initial suspicion, two agents “justified their commitment to his continued detention, despite the diminishing rationale, by insisting that they knew he was ‘bad.’”

In his response to the report at the time, included in the released document, CIA acting General Counsel John Rizzo offered a weak defense of the agency’s actions, saying it was possible officials “simply could have made - during a period of intense, frenetic activity in CTC - a mistake.” CTC is the agency’s Counterterrorism Center, which coordinates the CIA’s anti-terrorism activities.

The inspector general’s recitation of CIA errors begins with the initial decision to hold al-Masri without attempting to verify the premise on which he was detained: the suspicion by Macedonian security agents that he was an al-Qaida operative traveling on a false German passport.

But no one at the CIA bothered to look at his passport until three months into his detention, when an officer who’d interviewed al-Masri found the passport and more of his personal effects in an unopened pouch on the desk of another officer.

The official CIA chronology of the detention says the passport was then sent to agency experts, who “promptly determined that al Masri’s German passport was genuine.” A short time later, “CIA determined it had no basis to justify the continued detention of al Masri.”

Yet al-Masri’s detention continued for two more months, and it was almost that long before CIA officers told al-Masri they planned to release him.

Even before the agency learned that al-Masri’s passport was genuine, according to the report, a CIA officer whose name and title have been redacted from the report had concluded there was a “lack of compelling intelligence to warrant al Masri’s continued detention as a terrorist.” The officer “requested ALEC Station/CTC Headquarters concurrence to release al Masri.”

Instead, the two units suggested “additional areas of questioning” because they “could not resolve the issue of his terrorist affiliation.”

The report notes at one point that the CIA considered transferring al-Masri to the U.S. military as a “force protection threat” but decided against it because without confirmation that he was an al-Qaida member, the U.S. military was likely to release him “within hours.”

Indeed, throughout the rest of March and into April, while al-Masri languished: “Agency components continued to disagree about the exit strategy.” In other words, they were worried about how to release him.

It was not a topic left only to underlings.

In May, CIA officials including then-Director George Tenet met to discuss al-Masri. Later that month, then-Secretary of State Condoleezza Rice was briefed, and said al-Masri “should be repatriated quickly.”

A final cable notes they “did not find any information linking him or his customers with known terrorist individuals or organizations.” It isn’t clear what the term “customers” is referring to, though al-Masri had worked as a grocer and a mechanic.

Agents in the field were told to tell al-Masri he was to be released “to help mitigate his frustration and anger.” They dropped him off in Albania and told him to make his way back to Germany. Dakwar notes that that is the last official communication al-Masri has had with the United States.

Al-Masri received $80,000 from Macedonia for his mistreatment by its security personnel, a payment ordered by the European Court of Human Rights. He’s seeking an apology from the United States before the Inter-American Commission on Human Rights.

“This is the very least President Obama can do … before leaving office,” Dakwar wrote recently on the ACLU’s website.