American special operations analysts were gathering intelligence on an Afghan hospital days before it was destroyed by a U.S. military attack because they believed it was being used by a Pakistani operative to coordinate Taliban activity, The Associated Press has learned.

It's unclear whether commanders who unleashed the AC-130 gunship on the hospital - killing at least 22 patients and hospital staff - were aware that the site was a hospital or knew about the allegations of possible enemy activity. The Pentagon initially said the attack was to protect U.S. troops engaged in a firefight and has since said it was a mistake.

The special operations analysts had assembled a dossier that included maps with the hospital circled, along with indications that intelligence agencies were tracking the location of the Pakistani operative and activity reports based on overhead surveillance, according to a former intelligence official who is familiar with some of the documents describing the site. The intelligence suggested the hospital was being used as a Taliban command and control center and may have housed heavy weapons.

After the attack - which came amidst a battle to retake the northern Afghan city of Kunduz from the Taliban - some U.S. analysts assessed that the strike had been justified, the former officer says. They concluded that the Pakistani, believed to have been working for his country's Inter-Service Intelligence directorate, had been killed.

No evidence has surfaced publicly to support those conclusions about the Pakistani's connections or his demise. The former intelligence official was not authorized to comment publicly and spoke only on condition of anonymity.

The top U.S. officer in Afghanistan, Gen. John Campbell, has said the strike was a mistake, but he has not explained exactly how it happened or who granted final approval. He also told Congress he was ordering all personnel in Afghanistan to be retrained on the rules governing the circumstances under which strikes are acceptable.

The new details about the military's suspicions that the hospital was being misused complicate an already murky picture and add to the unanswered questions about one of the worst civilian casualty incidents of the Afghan war. They also raise the possibility of a breakdown in intelligence sharing and communication across the military chain of command.

White House spokesman Josh Earnest said questions about what the Defense Department knew about the clinic and whether it was communicated to personnel operating the gunship would be part of the Pentagon's investigation. He said President Barack Obama was expecting a "full accounting."

Pentagon officials declined comment.

The international humanitarian agency that ran the facility, Doctors without Borders, has condemned the bombing as a war crime. The organization says the strike killed 12 hospital staff and 10 patients, and that death toll may rise. It insists that no gunmen, weapons or ammunition were in the building. The U.S. and Afghan governments have launched three separate investigations. President Barack Obama has apologized, but Doctors without Borders is calling for an international probe.

Doctors without Borders officials say the U.S. airplane made five separate strafing runs over an hour, directing heavy fire on the main hospital building, which contained the emergency room and intensive care unit. Surrounding buildings were not struck, they said.

Typically, pilots flying air support missions would have maps showing protected sites such as hospitals and mosques. If commanders concluded that enemies were operating from a protected site, they would follow procedures designed to minimize civilian casualties. That would generally mean surrounding a building with troops, not blowing it to bits from the air.

What the new details suggest "is that the hospital was intentionally targeted, killing at least 22 patients and MSF staff," said Meinie Nicolai, president of the operational directorate of Doctors without Borders, which is also known by its French initials MSF. "This would amount to a premeditated massacre. ... Reports like this underscore how critical it is for the Obama administration to immediately give consent to an independent and impartial investigation by the International Humanitarian Fact-Finding Commission to find out how and why U.S. forces attacked our hospital."

By one U.S. account from the scene, American and Afghan troops were under fire in the area.

Nicolai said in an email exchange that the group's staff "reported a calm night and that there were no armed combatants, nor active fighting in or from the compound prior to the airstrikes."

Doctors without Borders has acknowledged that it treated wounded Taliban fighters at the Kunduz hospital, but it insists no weapons were allowed in. Afghans who worked at the hospital have told the AP that no one was firing from within.

The airstrike came as U.S. advisers were helping Afghan forces take Kunduz back from the Taliban, which had seized the city.

The U.S. military's cursory description of what transpired has changed over time.

Initially, the military portrayed the incident as an accident stemming from the fog of war. American forces in the vicinity were under attack, a U.S. military spokesperson in Afghanistan said in a statement, and called in an air strike "against individuals threatening the force. The strike may have resulted in collateral damage to a nearby medical facility."

Two days later, Campbell told reporters that "Afghan forces advised that they were taking fire from enemy positions and asked for air support from U.S. forces."

He added, "An airstrike was then called to eliminate the Taliban threat and several civilians were accidentally struck."

The following day, however, Campbell told the Senate Armed Services Committee, "To be clear, the decision ... was a U.S. decision made within the U.S. chain of command. A hospital was mistakenly struck. We would never intentionally target a protected medical facility."

Asked about the location of any U.S. troops on the ground, Campbell said, "We had a special operations unit that was in close vicinity that was talking to the aircraft that delivered those fires."

His remark did not make clear whether any American on the ground had a direct view of the hospital. Military officials declined to answer questions, citing the investigation.

According to the former intelligence officer, the commander on the ground has told superiors he was in the worst firefight of his career while taking fire from the building, which he said he did not know was a hospital. He requested the gunship strike. In that scenario, it's not readily apparent why his unit couldn't have retreated. The hospital is within a compound surrounded by a 12-foot wall that could have offered cover from fire emanating from one building.

The intelligence analysts who were gathering information about suspected Taliban activity at the hospital were located in various bases around Afghanistan, and were exchanging information over classified military intelligence systems. Typically, a decision to order a strike in a populated area would require many layers of approval and intelligence analysis of the potential impacts and civilian casualties.

It would be significant if U.S. intelligence had concluded that Pakistani spies were continuing to play an active role helping the Taliban. The U.S. and Afghan governments have long accused Pakistan of aiding the Taliban, but U.S. rhetoric on the issue has cooled over the past year as American-Pakistani counterterrorism cooperation has improved.

Yet it's theoretically possible that a staffer at a hospital in Afghanistan was working for Pakistan's intelligence service. Two days before the strike, Afghan defense officials accused Pakistan's intelligence service of playing a key role in the Taliban's seizure of Kunduz.

Nicolai said, "There were only Afghan staff and nine international staff, none of whom were from Pakistan, working in the hospital. There was absolutely nothing that indicated at any level, including at senior management, that any of our staff was working for Pakistani intelligence."

Disputes within the U.S. government about airstrikes have played out before. In December 2013, the U.S. military's Joint Special Operations Command bombed a group of people it considered militants, but whom outside groups claimed were civilians attending a wedding. Even after the CIA assessed that some civilians were killed in the strike, Pentagon officials continued to insist that all those hit were combatants.

The incident added an argument for some members of Congress who were resisting Obama's proposal to shift the CIA's drone killing program to the military.