The United States has ordered its diplomatic staff to leave Lahore, citing a specific security threat amid soaring terrorist violence in Pakistan.

Even though the US consulate in Pakistan's second largest city was closed for the Islamic holiday of Eid al-Fitr, non-essential staff were told it would not be safe for them to remain in their homes in the city.

They were ordered to move to the capital, Islamabad, where an embassy spokeswoman said it was unclear when the Lahore mission would reopen.

Diplomatic outposts in Peshawar and Karachi, which are considerably more volatile than Lahore, were not affected by the security warning.

US officials said they were unable to say for certain whether the alert was linked to an al-Qaida threat this week that prompted the US state department to shut down 19 missions in 16 countries in the Middle East and Africa.

On Thursday, a state department travel warning said several foreign and indigenous terrorist groups posed a potential danger to US citizens throughout Pakistan.

The withdrawal of staff from Lahore, the politically important capital of the Punjab province, comes after days of relentless terrorist strikes across the country.

On Friday, gunmen attacked the car of a politician in the south-western city of Quetta, killing nine bystanders and wounding 27. The politician, an ex-minister in the provincial government of Baluchistan called Ali Mohammad Jattack, was not hurt.

He told local media: "They killed innocent worshippers belonging to different communities. This is against humanity, it is brutality on the level of animals."

Quetta was still reeling from a tragedy on Thursday when 21 police officers were killed by a suicide bomber at a funeral for one of their colleagues who had been shot dead earlier that day.

Other attacks this week include the murder of 13 bus passengers by separatist militants as they travelled through the troubled province of Baluchistan. Also on Friday a suicide bomber attempted to blow himself up in a Shia Muslim mosque in Islamabad. The attacker was killed in a shootout with guards before he could detonate his explosive jacket. One guard was killed in the standoff.

Sunni sectarian terrorism is one of the main strands of Pakistan's increasingly alarming security crisis. But analysts are unsure what is driving the spike in violence. Many observers expected attacks by the Pakistani Taliban to decline after May's historic elections. During the campaign, politicians from parties regarded by Islamists as liberal and secular were attacked by Taliban gunmen and bombers.

Mainstream rightwing candidates were largely left untouched, including candidates from the ultimately victorious faction of the Pakistan Muslim League, led by the prime minister, Nawaz Sharif.

But despite the routing of the main secular parties and an early announcement by Sharif that he would negotiate with militants, attacks have soared. The government, which had hoped to focus on reviving Pakistan's moribund economy, has been put on the back foot. It has promised to announce a much anticipated counter-terrorism strategy next week.

Lahore, an attractive leafy city regarded as Pakistan's cultural capital, does not suffer the regular bomb blasts and killings experienced in other parts of the country, particularly the restive areas near the Afghan border where members of the Pashtun ethnic group dominate. However, Lahore does suffer periodic attacks. In July a bomb in "food street", where families gather to experience the city's famous cuisine, killed 50.

Western interests have also been attacked there. In August 2011 Warren Weinstein, a US aid contractor, was kidnapped outside his house. Ayman al-Zawahiri, the al-Qaida leader, later appeared in a video claiming credit for the kidnap and issued a series of demands for his return, including the release of all prisoners held by the US at the Guantánamo Bay detention centre. In December last year a Swedish charity worker was shot on her doorstep in the city and later died in hospital.

Lahore is home to one of America's most wanted men, a hardline Islamist preacher called Hafiz Saeed linked to the banned terror group Lashar-e-Taiba. The US has offered a $10m (£6.4m) reward for information leading to Saeed's arrest because of his alleged masterminding of the 2008 terrorist attacks in Mumbai, India. Despite the reward, Saeed lives openly in Lahore. On Friday he led Eid prayers at a gathering of hundreds of his supporters near the city's main cricket stadium.