Raymond Davis flown to US airbase after payments made to relatives of men shot dead by intelligence agent in Lahore

Raymond Davis, the CIA spy charged with murder in Pakistan, has flown out of the country after the relatives of two men he killed dropped charges in exchange for "blood money" of at least $2.3m (£1.4m) and help in resettling abroad.

Davis slipped out of Lahore on a special flight from the old city airport after being released from the sprawling jail where he had been held for almost 10 weeks amid a diplomatic storm that rocked relations between the two allies and sucked in President Barack Obama.

A Pakistani official said the 36-year-old US spy was bound for an airbase in Afghanistan, then on to the US.

Davis was freed under Islamic laws that allow a murderer to walk free on payment of compensation to the family of his victims. The acquittal took place during a closed hearing at Kot Lakhpat jail where no reporters were present.

"The court first indicted him, but the families later told the court that they have accepted the blood money and they have pardoned him," said Rana Sanaullah, the Punjab law minister.

The US secretary of state, Hillary Clinton, thanked the families for pardoning Davis and allowing the American to go. Speaking from Cairo, Clinton said the US had not paid to win Davis's release.

The dramatic case has become an obsession in Pakistan since Davis, a bulky former special forces soldier, opened fire on two men at traffic lights on 27 January. Davis claimed he acted in self-defence against robbers, but prosecutors said he shot one in the back as he ran away. Several officials said the men he killed were linked to Pakistani intelligence.

The deal to free Davis was an unusual mix of Islamic law and tense backroom negotiations between American and Pakistani spies and diplomats.

Court documents detailed payments of almost $1.2m to the mother, widow and eight siblings of Faizan Haider, while relatives of the other dead man, Muhammad Faheem, received a similar amount. A senior Pakistani official said compensation was also paid to the family of a third man killed by a US rescue vehicle, presumed to be driven by CIA employees.

It is believed the money was transferred by Pakistani authorities, pending reimbursement from the US, allowing Clinton to make her denial of payment on Wednesday.

Washington also undertook to facilitate the future resettlement of family members in the US or a Gulf state such as Dubai, the official added. "The Americans will be helpful to the families," he said. But the deal was also a defeat for US diplomacy, which had insisted Davis was a bona fide diplomat who enjoyed immunity from prosecution. In the early stage of the controversy, the US accused Pakistan of "illegally detaining" Davis, while Obama defended him as "our diplomat".

The carefully orchestrated legal events in Lahore belied weeks of negotiations between the CIA and Pakistan's Inter-Services Intelligence (ISI), which have been at barely concealed loggerheads over the incident. The legal manoeuvres were "a fig leaf", one official admitted.

The idea of a payment was first mooted between Pakistan's ambassador to the US, Husain Haqqani, and Senator John Kerry in February. But the arrangement first needed the co-operation of Pakistani intelligence, which seemed determined to press its advantage.

Relations between the two spy agencies had been fragile for months. In December the CIA station chief had to leave Islamabad after being named in the press; ISI officials were angry that their chief, General Shuja Pasha, had been named in a New York lawsuit brought by victims of the 2008 Mumbai attacks.

The ISI had been unaware of Davis's CIA role in Pakistan, where he was employed to protect operatives gathering information about groups such as Lashkar-e-Taiba, a militant Islamist group close to Pakistan's intelligence service and linked to terrorist attacks against India, and relations between the CIA and ISI were strained as a result. The CIA director, Leon Panetta, phoned the ISI chief, General Shuja Pasha, last month to try to smooth relations.

Media leaks in the Pakistani press during the stop-start trial kept the pressure on the US, such as the publication last weekend of the names and passport details of other "Raymonds" – Americans suspected of entering Pakistan under false pretences – in a newspaper. The report quoted "official sources".

In return for Davis's release, the ISI has obtained an undertaking from the CIA about covert operations on their turf, the Pakistani official said. "They will do nothing behind our backs that will result in people getting killed or arrested."

There were other indications that a deal had been worked out. The US embassy press release welcoming Davis's release was initially dated March 10 – around the same time a deal was struck in Washington.

Analysts also noted that General Pasha, who was due to retire this month, obtained an unusual one-year extension of tenure this week.

Kerry, head of the Senate foreign affairs committee, who is often used as a go-between in difficult issues, is thought to have raised the issue of compensation with the Pakistan government on a visit to Islamabad on 16 February. Kerry's visit, devoted to securing Davis's release, was initially believed to have been a failure. But US officials have been working behind the scenes since then at trying to secure the deal.

Kerry said: "This was a very important and necessary step for both of our countries to be able to maintain our relationship and remain focused on progress on bedrock national interests, and I'm deeply grateful for the Pakistani government's decision.

"We deeply regret the loss of life that led to this difficulty in our relationship and the demonstrations on Pakistan's streets, but neither country could afford for this tragedy to derail our vital relationship. We look forward to working with Pakistan to strengthen our relationship and confront our common challenges."

The US state department released a statement by the US ambassador to Pakistan, Cameron Munter, who accompanied Davis on the flight from Pakistan to Afghanistan. Munter thanked the families of their victims for pardoning Davis. "I am grateful for their generosity."

He stressed that the US justice department has opened an investigation into the shooting in Lahore.

He added: "Most of all, I wish to reaffirm the importance that America places in its relationship with Pakistan, and the commitment of the American people to work with their Pakistani counterparts to move ahead in ways that will benefit us all."

As night fell in Lahore, there was a small protest outside the US consulate where Davis claimed to work, led by demonstrators from the Jamaat-e-Islami, the country's main religious party. Further protests are expected after prayers on Friday.

Meanwhile, the CIA continued drone strikes in the tribal belt, firing three missiles at a car in North Waziristan that reportedly killed five people. It was the 16th drone strike in Pakistan this year.