A Pakistani court on Tuesday ordered the government not to release an American official arrested in the killing of two Pakistanis who allegedly tried to rob him, despite U.S. insistence that he has diplomatic immunity and has been detained illegally.

The Lahore High Court has ordered the government not to hand over the American diplomat, Raymond Davis, and to place him on the 'exit control list' to prevent him from leaving Pakistan.

The U.S. Embassy in Pakistan on Monday called for the immediate release of Davis, saying he is being unlawfully detained by authorities in the city of Lahore.

According to U.S. Embassy statement, on January 27, the diplomat acted in self-defense by shooting the two armed men on motorcycles who confronted him in an alleged robbery attempt. The diplomat had every reason to believe that the armed men meant him bodily harm. Minutes earlier, the two men, who had criminal backgrounds, had robbed money and valuables at gunpoint from a Pakistani citizen in the same area.

Davis was driving in a busy area known as Kartaba Chawk on Thursday when two boys on a motorcycle tried to rob him, Faisal Rana, a police officer, said.

However, Zulfiqar Hameed, a senior police official, said he is upset as Davis was not cooperating with investigators or answering questions, citing diplomatic immunity.

The U.S. Embassy has justified Davis' action, saying, When detained, the U.S. diplomat identified himself to police as a diplomat and repeatedly requested immunity under the Vienna Convention on Diplomatic Relations.

According to a statement released by the embassy, local police and senior authorities failed to verify the status of Davis with either the U.S. Consulate General in Lahore or the U.S. Embassy in Islamabad. Furthermore, the diplomat was formally arrested and remanded into custody, which is a violation of international norms and the Vienna Convention, to which Pakistan is a signatory, the embassy statement said.

The U.S. diplomat detained in Lahore is a member of the U.S. Embassy's technical and administrative staff, and therefore entitled to full criminal immunity and cannot be lawfully arrested or detained in accordance with the convention, another embassy statement said.

The arrest of Davis and a possible prosecution could jeopardize the relationship between Pakistan and the United States. Pakistan is a crucial ally for the United States in its efforts to stabilize Afghanistan.

The issue could also be politically explosive for the government of President Asif Ali Zardari as hardline Islamic groups have warned authorities against releasing Davis.

Some members of the Pakistani media, which have in the past accused U.S. aid workers of being spies, have also called for Davis to be put on trial in Pakistan.

Zardari met a U.S. Congressional delegation on Monday and had discussed the sensitive issue.

According to a government spokesman, the president has suggested that Davis should be put on trial as the matter is already before the courts.