Two men convicted of slaughtering 40 people during a bank robbery in February were hanged Monday morning inside a Kabul prison, the first such sentence carried out by the government of President Hamid Karzai since the end of Taliban rule a decade ago.

The government has been reluctant to administer capital punishment in an effort to distance itself from the Taliban, who carried out primitive public executions by stoning and shooting in crowded public stadiums. But Karzai, facing strong public pressure in this case, signed the men’s execution warrants after they were sentenced to death in court.

The National Intelligence Police, which announced the hangings in a statement, described the men as “terrorists” who had killed “40 of our innocent countrymen” and injured 78 others during the attack. They said the assailants had been brought to justice and that “Mr. Karzai accepted the decision of the court.”

The massacre at a Kabul Bank branch in Jalalabad city was an especially brutal and shocking crime, even in a country used to decades of armed conflict. It aroused nationwide outrage and demands for the attackers to be put to death.

One of the executed men, identified as a Pakistani named Zar Ajam, was captured on security cameras, wearing an Afghan police uniform and systematically shooting customers as they cowered on the floor. Presented later at a police news conference, he said he had enjoyed killing them.

The second man to be executed was identified as Matiullah from Afghanistan’s Kunar province. A third Afghan was given a 20-year prison sentence, a fourth attacker was shot by security guards, and a fifth detonated a suicide vest and killed himself. Some officials had earlier described by the group as Taliban insurgents, but police did not do so Monday.

Police said the body of Zae Ajam was handed over to the embassy of Pakistan in Kabul on Monday afternoon, and the body of Matiullah was given to his relatives.

Monday’s hanging was not the first case of capital punishment during the Karzai government. A small number of convicted murderers and other criminals have been executed by firing squads inside prison compounds, but there has been no public announcement.

Several years ago, when an Afghan Muslim man faced a possible death sentence for converting to Christianity, the Karzai government quietly arranged for him to be sent to Italy after international donors and rights groups expressed outrage at his plight.

This time, however, the fury of the Afghan public, and the formal death sentence order from the court system, came at a time when Karzai has become highly critical of Western military actions and foreigners’ presence in Afghanistan. He expressed no qualms about signing the execution order.

A spokesman for the Taliban issued an email statement to the media late Monday expressing condolences for the two executed men and warning that it was the “duty of all mujaheddin,” or fighters for their cause, to seek revenge against those who were behind their deaths.

“The Islamic Emirate of Afghanistan strongly condemns the executions, and revenge for the blood of our martyrs is our priority,” the statement said. It blamed the “puppet government” in Kabul for the deaths of the men, but it also said their “martyrdom is a great source of pride” and the achievement of a “great wish and hope, which has now come true.”

Salahuddin is a special correspondent.