Tahir Ahmad Naseem was killed by a man who shouted he was an “enemy of Islam” before opening fire.
Blasphemy is legally punishable by death in Pakistan, though no one has been executed for it. However, accusations of blasphemy have often led to violent attacks.
Video shared on social media of the grisly scene shows Naseem’s body slumped over the court’s seats.
The person who killed Naseem has only been identified as Khalid. It was not clear how Khalid brought a loaded gun into the court.
Naseem was first accused of blasphemy by a teenager named Awais Malik.
Naseem and Malik struck up a friendship online while Naseem was in the United States. Malik told the BBC that he and Naseem had met in person at a shopping mall in Pakistan to discuss his views on religion. The conversation was alarming enough for Malik to go to the authorities and open a case against Naseem.
Naseem was born into the Ahmadi sect but had left it and then claimed to be a prophet himself.
The Ahmadis are a persecuted minority in Pakistan and have been victims of the country’s draconian laws. There are about half a million Ahmadis in Pakistan, according to a study by Human Rights Watch.
The Ahmadi community leader suggested to the BBC that Naseem had been mentally ill and had uploaded videos on social media claiming to be a messiah.