Raymond Davis, the CIA spy charged with murder in Pakistan, has been freed after the families of two dead men agreed to drop charges in exchange for financial compensation.

The law minister of Punjab province, Rana Sanaullah, made the announcement hours after Davis appeared at a makeshift court in the jail where he was being held.

Davis was freed under the Islamic "blood money" provision of Pakistani law, whereby an accused murderer can be freed on payment of financial compensation to the family of the victim.

A senior Pakistani official said the US spy had since left the country and was en route to Afghanistan on board a special flight.

Officials said the US paid in the region of $700,000 (£436,000) to each of three families whose relatives were killed. Two were shot dead by Davis and a third was hit by a rescue vehicle.

The official said Washington had also agreed to "be helpful" to immediate family members who may wish to leave Pakistan for the US or the Gulf.

The sudden release of the 36-year-old former green beret is the dramatic conclusion of a case that has become a national obsession in Pakistan since Davis opened fire on two men in Lahore on 27 January, killing both of them.

Davis claimed he was acting in self-defence against robbers but Pakistani prosecutors charged him with murder, saying the evidence suggested he intended to kill the two men.

Some Pakistani officials said the two were linked to Pakistan's ISI spy agency, which quickly became embroiled in a barely concealed row with the CIA.

The case has become a major block to already fragile relations between Pakistan and the US, with officials from Barack Obama down insisting that Davis was a diplomat and therefore entitled to immunity. Pakistani officials were reluctant to declare Davis's status but the former foreign minister, Shah Mehmood Qureshi, insisted he did not qualify for protection.

A lawyer for one of the families told a local television station that the families had been taken to the jail and forced to sign the pardon papers.

Sanaullah said his government played no part in Davis's release. But Najam Sethi, a respected analyst, said on Twitter that chief minister Shahbaz Sharif had played a "key secret role".