Late in the evening of 26 November 2008, David Headley, a 48-year-old American living in Lahore, received a text from a man he knew as Sajjid, a senior militant in the banned Lashkar-e-Taiba organisation. "Turn on the television," it said.

Headley, a member of the group since 2002, did so and saw footage of carnage in Mumbai. He forwarded the text to another militant. Then he sat down, watched the scenes of mayhem and exchanged emails with his wife.

Headley, of mixed Pakistani and US parentage, had played a central role in preparing the operation he was watching. Over the previous two years, he had made nine trips to India to scout out targets. The tall, pony-tailed, multilingual US graduate was the perfect spy for the militant organisation, particularly after changing his name from Daood Gilani.

On one trip, he had stayed with his Moroccan third wife at the Taj Mahal Palace hotel, where 31 would die. On another he had videoed the Chhatrapati Shivaji train station, where 58 would be gunned down. In April, he had spent five days taking boat trips off Mumbai, bringing back fish for his landlady – and finding the perfect location for the attackers to put ashore before fanning out across the city. On his final trip, in July, he had looked over a Jewish centre, and a cafe popular with tourists.

On his return to Pakistan he had met his militant associates in a safe house and handed them a memory stick with images and photographs of the targets. But this was not the only post-mission debrief the smooth-talking former video shop owner from Philadelphia had. According to the 106-page transcript of Indian investigators' interviews with Headley earlier this year, even before meeting Lashkar-e-Taiba commanders, Headley had sat down with "Major Iqbal", an officer in Pakistan's Inter-Services Intelligence Directorate (ISI), the main military intelligence agency. Nor was this the first meeting with the man he called his handler. Before and after almost every visit to India, Headley told his questioners, he had met Iqbal to receive instructions or brief him.

When on a mission, Headley said, he usually recorded images of potential targets on two memory sticks, one for Lashkar-e-Taiba, the other for the ISI. And one reason that he had been able to avoid detection was because in 2007 Iqbal had trained him in clandestine techniques. The skills learned on the streets of Lahore and put to use in Mumbai, Delhi, Pune and other cities across India only took Headley so far, however. Eleven months after the attacks, now involved in plots for attacks in the west, he was arrested in Chicago on his way back to Pakistan.

Headley's testimony, recorded in 34 hours of interviews with Indian investigators in the presence of FBI officials in June this year, does not just detail relations between the ISI and the perpetrators of the Mumbai attacks. It also provides a glimpse of the workings of one of the world's most secretive militant organisations. The attacks, his testimony suggests, grew out of the pressure on commanders of Lashkar-e-Taiba to wage a wider war against the west.

Lashkar-e-Taiba was formed in the early 1990s to send Islamist militants across the de-facto border which separates Indian from Pakistani-controlled Kashmir. Since 2005, Headley says, splinter groups had been breaking away from the group, the biggest militant organisation in Pakistan and the closest to the security establishment. These dissidents were close to radical groups such as al-Qaida or those that were to become the Pakistani Taliban. Senior commanders "had a serious problem holding the LeT [together] and convincing them to [only] fight for Kashmir and against India," Headley told his interrogators. The ISI, he told his interrogators, was equally concerned and under "tremendous pressure to stop the integration of Kashmir-based outfits with Jihadi-based outfits" and hoped "to shift … the theatre of violence from the domestic soil of Pakistan to India".

However, despite detailing close contacts with his handler, the picture that emerges from Headley's interrogation is of a chaotic and complex relationship between the ISI and the militants, with the former not always fully aware of developments. Headley told his questioners that Lieutenant General Ahmed Shuja Pasha, the director general of the ISI, visited Zaki ur Rehman Lakhvi, the operations chief of LeT, in prison after the attacks in an attempt to "understand" the operation, implying that top level officers were not fully informed. Pasha replaced General Ashfaq Parvez Kayani as head of the ISI just over a year before the attacks. Security sources have told the Guardian that they believe the ISI command lost "ownership" of the operation around that time.

Stephen Tankel, the author of a forthcoming book on LeT, said: "The ISI had more control over the LeT than they admit publicly, but probably less than they'd like to have privately."

The ISI denied any links to the Mumbai attacks yesterday.

Headley told his interrogators that he had formally joined Lashkar-e-Taiba in 2002 after seeing a banner advertising a fundraising drive by the group at the mosque where he prayed, and after attending lectures given by its founder and leader, Hafiz Saeed. Headley's ambition was to fight in Kashmir, and he had military training at camps in north-east and north-west Pakistan.

By January 2006, he had still not been given a combat mission and was feeling demoralised. When detained by the Pakistani police after travelling close to the Afghan border, Headley was interviewed by an ISI officer called "Major Ali" to whom he recounted his involvement in Lashkar-e-Taiba and "ongoing plans to go to India".

He was soon freed and was contacted on his return to Lahore by Major Iqbal. After a two-hour meeting with Iqbal and his immediate superior, a "Lieutenant Colonel Hamza", Headley travelled to America, where he changed his name and then returned to Pakistan where Iqbal arranged for his training.

In June 2006, Headley said, he returned to the US to get an Indian visa and then, in December, having received $25,000 from Iqbal, he travelled to India with the cover story of opening a visa facilitation agency in Mumbai. On his return, he gave a 2GB memory stick containing images of a variety of locations in Mumbai to Iqbal. Headley did not have the impression that any definite plan for attacks yet existed, he told his interrogators. In a safe house, Headley did, however, spend several hours viewing images of potential targets in India with Zaki ur Rehman Lakhvi, the LeT military operations chief, before returning to Lahore to continue training with the ISI.

Over the next year, Headley was to make a series of trips to Mumbai.

Tensions within Lashkar-e-Taiba were building, with one senior militant insisting that the group abandon its focus on India and Kashmir for a broader agenda. Lakhvi, the operations chief, argued that the "jihad" in Kashmir was more legitimate and important.

By September 2007, Headley's instructions from "Sajjid", his immediate handler in Lashkar-e-Taiba, were more precise, and he made an extensive study of the entries and exits of the Taj Palace. But the operation still involved only one or two militants who would try to make their escape after their attack, Headley said.

One meeting of four top militants he attended, he remembered, took place in Rawalpindi on the day when Benazir Bhutto was assassinated, just a mile or so away. All present expressed their fervent desire that the former prime minister might die of her wounds, he remembered. Hours later, she did.

By the spring of 2008, the plan Headley heard his fellow militants discussing involved "multiple locations and multiple attackers" who would be sent by sea. In April, Headley scouted the landing sites, returning to give the images to Major Iqbal of the ISI and the GPS co-ordinates he had logged to Lashkar-e-Taiba high command.

In June, he was told a new target had been added, another consequence of the fierce internal debate within the group. It was a Jewish centre, the Chabad House.

There was also the Leopold Cafe. The attackers were still supposed to escape after their strike, so Headley said he was told to scout Chhatrapati Shivaji station, from where trains headed north.

By August, after further rows about attacking the Jewish centre, it was decided by Lashkar-e-Taiba commanders that the strike would become a suicide mission and the station became a target, not an escape route.

The training of the 10 attackers was adapted to include indoctrination on martyrdom, Headley said.

On the first attempt, the boat carrying the attackers to Mumbai foundered. On the second, it were nearly discovered by Indian coastguards. On the third, the attackers reached Mumbai, guided by the GPS co-ordinates Headley had provided. Hours later, Headley received the text telling him to turn on the TV.

Headley infiltrated drugs gangs for American authorities in the late 1990s after being jailed for heroin trafficking, and went on after the Mumbai attacks to become involved with a plot by Pakistani militants linked to al-Qaida to attack in Europe. He faces the death sentence. He has agreed to talk to authorities about his previous life in an attempt to avoid the death penalty.

Profiles

David Headley

The 50-year-old militant was born Daood Gilani in Washington to a Pakistani father and an American mother. He attended a prestigious military boarding school in Pakistan but returned to the US, where he was convicted of drug trafficking in 1988 and 1997. In return for a reduced sentence, Gilani became an informant for the Drug Enforcement Administration.

He started travelling to Pakistan to develop intelligence on major heroin smugglers, but this also led him into radical Islamist circles and he started to associate with Lashkar-e-Taiba, one of the most active Islamist terrorist groups in south-east Asia. From 2002 Gilani spent at least five stints at its training camps in Pakistani-controlled Kashmir, some lasting three months, where he was schooled in ideology, explosives and counter-surveillance.

In 2006 Gilani changed his name to David Headley, ostensibly to disguise his background, and started travelling to India and Pakistan to help plan the November 2008 Mumbai attacks.

He reportedly has three wives – a Pakistan, an American and a Moroccan – two of whom tried to warn US officials of his militant links before the attack. But their warnings went unheeded for reasons that remain unclear.

In early 2009 Lashkar-e-Taiba deployed him to Denmark to plot against a newspaper that published cartoons of the prophet Muhammad. But he was detected by British intelligence and subsequently arrested by the FBI.

US officials describe him as a chameleon-like figure with a knack for deception and skulduggery.

"He's not an Islamic terrorist in the classic sense," one told the Washington Post recently.

General Ashfaq Kayani

The taciturn, chain-smoking Kayani is arguably the most powerful man in Pakistan. Since replacing Pervez Musharraf as army chief in November 2007 he has steadily expanded his authority. Last year he dispatched troops into Swat and South Waziristan to oust the Taliban from their mountain lair; more recently, he helped the US increase drone strikes. The army's budget is up 25%; this summer the prime minister, Yousaf Raza Gilani, granted Kayani an unprecedented three-year extension of tenure. The army was praised for its response to the recent floods.

Yet troubling ambiguities persist. Kayani headed the ISI between 2004 and 2007, a time when the spy agency faced persistent accusations that it was playing a "double game", cracking down on some groups while harbouring others. Kayani insists those ties have been severed but western officials remain sceptical, saying the army's world-view remains India-centric. The army's refusal to disarm "weapons" such as Lashkar-i-Taiba prove this, they say.

Kayani has vowed to pull the army out of politics and close the ISI's notorious "political cell". Yet Kayani himself has swelled into a political figure of import. He recently requested asked President Asif Ali Zardari to purge the most corrupt minister from his bloated cabinet, but persistent rumours of a military coup have proven unfounded – analysts say Kayani doesn't want to wield power directly. At any rate, there is no need. As it overshadows a weak civilian government, the army enjoys unchallenged control over the issues that are closest to every general's heart: policy on Afghanistan, India and the secretive nuclear programme.

Lieutenant General Shuja Pasha

Pasha has controlled the formidable Inter-Services Intelligence (ISI) agency since October 2008. His spies are on the frontline of the fight against Islamist militancy – ISI buildings and employees have been attacked numerous times – yet also face frequent accusations of fostering favoured extremists. Pasha is the embodiment of these contradictions. A short man with a shy smile, he is a fluent German speaker and considered close to his boss, General Kayani. Earlier this year the two travelled to Kabul, offering to help broker Afghan peace talks with the Haqqani militant group. The Punjabi general preaches peace with India – "There will not be a war," he said in 2009 – yet has continued the agency's long-standing support, or at least tolerance, for Lashkar-e-Taiba. Like Kayani, his boots are firmly under the desk: due to retire last March, he was given a one-year extension of tenure.

Hafiz Saeed

As a young university lecturer, Saeed was drawn into the murky world of Islamist militancy during the 1980s "jihad" against Soviet troops in Afghanistan. Now he is Pakistan's most notorious Punjabi militant, a pudgy man with a thick beard who operates openly from his Lahore base, addressing rallies and meeting selected journalists. Nominally Saeed heads Jamaat ud Dawa, an Islamist charity, but is widely considered the effective leader of Lashkar-e-Taiba, a fiercely ideological and strictly disciplined group that cut its teeth attacking Indian soldiers in Kashmir in the 1990s. In recent years it has broadened its operations to include attacks on western troops in Afghanistan and western tourists in Mumbai. LeT has long-standing links with the ISI. Saeed was briefly detained in 2002 for his alleged role in an attack on the Indian parliament, and again in 2008 after the Mumbai attacks. In 2009 Interpol issued a "red notice" for his arrest. Profiles by Declan Walsh