The heaviest toll was inflicted in the Pakistani city of Quetta, in western Baluchistan Province, where at least 30 people died in a suicide attack at the funeral of a policeman who had been killed just hours earlier.

At the eastern end of the border, in the Afghan province of Nangarhar, a bomb exploded at a graveyard where people had gathered to pay their respects to a slain relative. Fourteen women and children from the same family were killed.

Reporters in Quetta described scenes of chaos and devastation after the attack on the police funeral. At least 21 officers were among the 30 killed, including a deputy chief in charge of field operations, Fayyaz Ahmed Sumbal.

Shahidullah Shahid, a spokesman for the Pakistani Taliban, claimed responsibility for the Quetta attack and said that the group would continue to target police officials, according to local news media outlets.

While the attack underscored Quetta's fragile security situation, other parts of Pakistan are also turbulent. According to a warning issued Thursday, the State Department has ordered most of its diplomats in Lahore, east of Quetta, to leave in response to a terrorist threat against the American Consulate there.

At this point, it does not appear that the threat against the consulate is related to a broader terror alert that prompted the State Department to close 19 diplomatic missions in the Middle East, Africa and Asia, a senior Obama administration official said.

"The Department of State ordered this drawdown due to specific threats concerning the U.S. Consulate in Lahore," the warning stated. In dangerous countries, like Pakistan, it is not uncommon for the United States to temporarily close consulates after receiving credible threats.

Except for a small number of emergency personnel, the diplomats in Lahore were moved to Islamabad, the Pakistani capital, the administration official said. The threat against the consulate was first reported by CNN.

Thursday's bloodshed started with the killing of a junior police official, Muhib Ullah. He was shot by unidentified gunmen on his way to a market, and four of his children were wounded. The assailants escaped unharmed.

Hours later, as the city's police leadership gathered for Mr. Ullah's funeral in the Police Lines, a relatively secure area that houses police and provincial officials, a suicide bomber slipped through the security cordon and set off his explosives.

The spate of violence has rattled the government of Prime Minister Nawaz Sharif, who ordered Interior Minister Chaudhry Nisar Ali Khan to visit Quetta soon. Mr. Sharif also asked him to present the final draft of a much-awaited national counterterrorism strategy on Aug. 30.

Critics say the lack of such a strategy has resulted in confusion and lack of consensus about how to deal with the terrorists.

Opposition politicians urged the government to immediately convene a national conference of all political parties to come to a policy consensus. "The delay is causing more acts of terrorism," said Syed Khurshid Shah, an opposition lawmaker belonging to the Pakistan Peoples Party.

The attack in Afghanistan occurred in the Ghanikhel district, near the border with Pakistan. The victims were visiting the grave of a relative on the first day of Id al-Fitr, the Islamic holiday marking the end of the holy month of Ramadan.

Provincial authorities said a bomb apparently planted on a grave exploded once the family gathered around it.

"My family is finished," Hajji Ghalib, a relative of the victims, told The Associated Press. "These people are inhuman."

Suspicion fell on the Taliban, who the United Nations says are responsible for the majority of civilian deaths in Afghanistan.

The 14 victims, seven women and seven children, had been visiting the grave of an elder who was assassinated by the Taliban this year. President Hamid Karzai denounced the bombing as "a cowardly act by the enemies of the people of Afghanistan who are not part of any religion."

Salman Masood reported from Islamabad, and Declan Walsh from London. Matthew Rosenberg contributed reporting from Kabul, Afghanistan, Khalid Alokozay from Jalalabad, Afghanistan, and Eric Schmitt from Washington.