The American, Tahir Naseem, died of his wounds before he could be taken to hospital while the gunman, Faisal Khan, was taken into custody.
The US State Department said Naseem was standing trial after being “lured to Pakistan” from his home in Illinois and entrapped by the country’s controversial blasphemy law, which international rights groups have sought to have repealed.
The US statement did not elaborate on the circumstances in which Naseem came to be in the South Asian country.
The blasphemy law calls for the death penalty for anyone found guilty of insulting Islam. But in Pakistan, the mere allegation of blasphemy can cause mobs to riot and vigilantes to kill those accused.
“We are shocked, saddened, and outraged that American citizen Tahir Naseem was killed yesterday inside a Pakistani courtroom,” read the State Department statement, which was released on Thursday.
Pakistani officials said Naseem was charged with blasphemy after he declared himself Islam’s prophet. Police in Peshawar, who originally identified him as Tahir Shameem Ahmed but later corrected themselves, said he was arrested two years ago.
The assailant was also initially identified incorrectly, as Khalid Khan. It was later learned his real name is Faisal Khan. It was not clear how he managed to enter the courtroom and get past security with a weapon.
“We urge Pakistan to immediately reform its often abused blasphemy laws and its court system, which allow such abuses to occur, and to ensure that the suspect is prosecuted to the full extent of the law,” said the statement issued by Cale Brown, the State Department’s principal deputy spokesperson.
However, in deeply conservative Pakistan, any attempt to even amend the blasphemy law to make it more difficult to bring charges or abuse it has brought mobs out on the street.
At the rally in Peshawar, the demonstrators carried signs praising Khan for the killing, calling for his immediate release from jail and saying he killed Naseem because the government was too slow in prosecuting blasphemy cases.
Although Pakistani authorities have yet to carry out a death sentence for blasphemy, there are scores of accused on death row. Most are Muslims and many belong to the Ahmadyya sect of Islam, reviled by mainstream Muslims as heretics.
Religious minorities are increasingly under attack even as Prime Minister Imran Khan preaches a “tolerant” Pakistan. Observers warn of even tougher times ahead as Mr Khan vacillates between trying to forge a pluralistic nation and his conservative Islamic beliefs.
A Punjab governor was killed by his own guard in 2011 after he defended a Christian woman, Asia Bibi, who was accused of blasphemy. She was acquitted after spending eight years on death row in a case that drew international media attention. Faced with death threats from Islamic extremists upon her release, she flew to Canada to join her daughters last year.