Suspected gang members killed 39 people in two days in Pakistan’s largest city, with many of the victims showing signs of torture, officials said Thursday.

The gangs are allegedly affiliated with Karachi’s main political parties and have been blamed for a surge in killings in recent months. The government, which is also grappling with a faltering economy and an active Islamist insurgency, has been unable to stop the violence.

The unrest illustrates the precarious state of Pakistan’s stability at a time when the United States wants the nuclear-armed country to step up its fight against Taliban militants who stage cross-border attacks against foreign troops in Afghanistan.

Seventeen people were killed in Karachi on Wednesday and 22 on Thursday, said Saud Mirza, police chief in the southern port city of about 18 million. Many of the victims were tortured, shot in the head and stuffed in burlap sacks that were left on the street, he said.

A resident in one of the neighborhoods that has experienced much of the violence said people were afraid to leave their homes. He spoke on the condition of anonymity because he feared being targeted.

The latest round of violence seemed to be driven by a mixture of political and criminal motivations, said Sharfuddin Memon, the security adviser to the government in Sindh province, of which Karachi is the capital.

“Gangs operating in the city are involved in the fresh killing,” Memon said. “They are kidnapping people for different reasons, torturing and killing.”

A senior leader of the most powerful political party in Karachi, the Muttahida Qaumi Movement, blamed some members of the ruling Pakistan People’s Party for the recent violence. Raza Haroon claimed the killings were being carried out by a committee set up by the Pakistan People’s Party to control violence in Lyari Town, a poor area and a ruling party stronghold.

“Now the gangs have so much courage that they have started killing Urdu-speaking people ruthlessly,” Haroon said at a news conference.

A large number of the Muttahida Qaumi Movement’s supporters are Urdu-speaking descendants of people who came to Karachi from India soon after the birth of Pakistan in 1947.

“We demand the government stop this horrible genocide of Urdu-speaking people,” Haroon said.

Sharjeel Memon, Sindh’s information minister and a senior member of the Pakistan People’s Party, declined to respond to the allegations.

Supporters of the Pakistan People’s Party have been targeted by the violence as well.

A former national lawmaker from the ruling party, Waja Kareem Dad, was gunned down Wednesday evening, according to Sharfuddin Memon.

The recent violence came after the Muttahida Qaumi Movement left the federal coalition led by the Pakistan People’s Party in late June and joined the opposition.

Karachi has a long history of political, ethnic and sectarian violence, but the recent wave is high by historical standards. More than 300 people were killed in July.

Violence also flared again in Pakistan’s northwestern tribal regions along the Afghan border, where the Taliban and other militants have bases.

Pakistani army chief Gen. Ashfaq Kayani announced Thursday that an operation in the Kurram tribal region had ended in success. The military operation there has killed more than 200 militants since July, officials said. The United Nations has said thousands of civilians were displaced.

The army has staged multiple operations in nearly all parts of the tribal belt to push out insurgents, but with limited success. The army has declared victory in various operations, only to resume fighting later when militants regroup.

— Associated Press

Zarar Khan in Islamabad contributed to this report.