KABUL, Afghanistan -- It burned white hot as a human-rights issue at the height of the Afghan war, sparking a political crisis that in 2009 nearly toppled Stephen Harper's minority government.

Five years on, the controversy that surrounded Ottawa's handling of the Taliban prisoner file -- in particular the nagging questions about whether they were tortured at the hands of their Afghan jailers -- faded more quickly from the public consciousness than the conflict itself.

Still, it remains a sensitive, lightning-rod issue in the back rooms, especially for those concerned about the judgment of history.

One question remained unanswered: just how many prisoners were there?

The answer -- like the war itself -- is complicated.

According to the Foreign Affairs Department, there were 1,023 individuals captured. The Canadian military, on the other hand, says some 1,069 prisoners were caught in their dragnet between 2001 and 2011.

For years, the true total was a closely guarded secret, a mission-critical piece of intelligence that was -- in the eyes of those conducting the war -- too valuable to disclose publicly, lest it fall into the hands of the enemy.

Some partial figures were posted online in 2010, but a complete picture has never come fully into focus until now.

National Defence and Foreign Affairs records, uncovered by The Canadian Press through the Access to Information Act, reveal not only the final tallies, but also offer a fresh, detailed perspective on the final days of Canada's monitoring program in both Kandahar and Kabul.

As the controversy raged at home, it might well have saved lives, federal documents show: diplomats who were on the ground at the time reported that some Afghan intelligence officers grew reluctant to touch prisoners captured by Canadians, for fear they would face repercussions.

On the other hand, it exposed an ugly indifference to those whose hands may or may not have been stained with Canadian blood. Some were bona fide killers, while others were likely just shady types who happened to test positive for gunshot residue. Telling them apart was not easy.

Amnesty International and the B.C. Civil Liberties Association fought long, protracted battles with the Harper government in an attempt to halt the transfer of prisoners to the Afghans. The human-rights campaign played out over several years in the courts and before a military watchdog agency.

In the end, both groups took comfort in moral -- not legal -- victories.

"I think Canada really lost its innocence in the detainee controversy," said Paul Champ, who served as lawyer for both groups.

The government did not consider the human rights of prisoners a priority when the Kandahar mission first unfolded, but soon came to grudgingly accept its responsibility, Champ said.

"Unfortunately, throughout this, the government's response was more about building a case of plausible deniability rather than seriously addressing the torture issue and claims," he said. "Above all, it was shameful."

The debate challenged and confronted Canadians in a way that rarely happens, he added.

"It upset many Canadians because it undermined our image of ourselves as a human rights leader in the world, and it forced many Canadians to take a close at whether our actions were matching our rhetoric."

Unlike the 1990s scandal in Somalia, there were no allegations of Canadians abusing prisoners. The central issue was whether Canada was complicit in allowing the Afghanistan authorities to mistreat their own people -- a distinction that perhaps made the issue easier for some to ignore.

Under international law, a country that hands over to a prisoner to certain torture is liable for war crimes prosecution.

At first, Canada wanted nothing to do with prisoners.

An agreement, reached in late 2005 just before the Kandahar combat mission, dictated that the army would deliver those it captured to local authorities, including the police and Afghanistan's notorious intelligence service, the National Directorate of Security.

There was no followup mechanism to ensure they were not abused. When the Globe and Mail newspaper published reports of torture in April 2007, a political brush fire erupted in Ottawa, subsiding only once the Harper government bowed to pressure and signed a revised agreement with the Afghans to establish a monitoring regime.

For the governing Conservatives, the issue refused to go away. In 2009, diplomat Richard Colvin fanned the flames with testimony before a parliamentary committee that accused the government of turning a blind eye to torture in Afghan jails and trying to cover it up.

That, combined with the government's subsequent refusal to release documents publicly, brought the opposition parties to within a hair's breadth of toppling Harper's minority government -- a fate the prime minister avoided by proroguing the House of Commons.

A year after combat operations ceased in Kandahar, Canadian diplomats continued to track prisoners behind the scenes through both the U.S. and Afghan detention systems to ensure that they weren't being tortured.

The last Canadian-captured prisoner to be handed over to the Afghans was convicted and sentenced by a court in Kandahar on May 29, 2012, almost a year after Canada's troops handed over responsibility for the province to U.S. forces.

Officials did one last interview with the prisoner the following month at the city's notorious Sarpoza prison.

"With this visit, Canada fulfilled its detainees monitoring requirements in Kandahar," said a Foreign Affairs briefing dated June 27, 2012.

The official "thanked prison staff for their co-operation over the past six years" -- a courteous gesture steeped in irony, given the allegations of torture, abuse and complicity in a pair of massive Taliban jailbreaks that swirled around the medieval fortress of Sarpoza and the nearby Afghan intelligence agency headquarters.

In September 2012, the Afghans took over control of the Kabul-area detention centre at Parwan, which was "designed to hold Afghan nationals indefinitely," said a briefing note to Foreign Affairs Minister John Baird.

Monitoring was to continue until the Canadian-captured prisoners were "all sentenced or released from custody."

As international forces prepare to withdraw from Afghanistan entirely by the end of 2014, concern persists in human rights circles about how diligently the Afghans will police the treatment of prisoners.

"The international forces have helped put more scrutiny on issue of treatment in Afghan-run detention facilities, particularly the treatment of security-related (and) conflict detainees," said James Rodehaver, the deputy director of the UN's human rights office in Kabul.

"And with the international forces drawing down, there is a concern that scrutiny will diminish and it will come back to simply the human rights actors in the country as the only ones (who are) able to put in that scrutiny and to provide assistance to the government to deal with mistreatment in facilities."

That the Afghans were now calling the shots was underscored dramatically a few weeks ago when a detention review board ordered the release of 37 prisoners, a portion the 81 detainees that the U.S. and NATO considered dangerous and a threat to the country's security.

They were being let go without trial or further investigation in an apparent bid to build up good will during secret peace talks with the Taliban.

"This extra-judicial release of detainees is a major step backward in further developing the rule of law in Afghanistan," said ISAF commander Gen. Joe Dunford.

Resentment that as many as 60 western troops were wounded or killed trying to capture and collect evidence on the high-value targets was never far from the surface in the public quarrel that followed the decision.