Image copyright EPA Image caption Two police officers were killed in the attack

Gunmen have killed at least four people in an attack on the Chinese consulate in the Pakistani port city of Karachi.

Gunshots were heard at about 09:30 local time (04:30 GMT) outside the consulate in the upmarket Clifton area. Police shot dead three attackers.

Separatist militants who oppose Chinese investment projects in western Pakistan say they carried out the attack.

In another incident on Friday, at least 30 people were killed in a bomb attack in north-west Pakistan.

The blast occurred in a mostly Shia neighbourhood in Orakzai district. Police say a suicide bomber on a motorbike drove into a crowded marketplace.

Pakistan's Shia minority has often been targeted by Sunni extremists.

What happened in Karachi?

Three gunmen tried to enter the consulate but were stopped by guards at a checkpoint, reports said. Two of those killed in the attack were police officers.

Image copyright Xinhua Image caption A burning vehicle near the attack site

Eyewitnesses reported seeing a blast, and local TV channels broadcast images of a plume of smoke. There is a heavy police presence in the area which has been cordoned off.

All the staff inside the consulate are safe, China said. The government condemned the attack on its mission and the foreign ministry in Beijing called for extra measures to protect Chinese citizens in Pakistan.

"At the same time we mourn the deaths of the Pakistani police and think of their families at this time," a spokesman said.

But the spokesman was keen to praise Pakistani security forces for its efforts to protect the consulate.

A separatist group, the Balochistan Liberation Army, said it had carried out the attack. It is one of a number of separatist groups operating in the province, which has seen a long-running nationalist insurgency.

"We have been seeing the Chinese as an oppressor, along with Pakistani forces," a spokesman for the group told the AFP news agency.

Over the years, construction projects and Chinese workers in Balochistan have been repeatedly targeted by militants. Most recently, a suicide bombing in August injured a number of Chinese engineers.

So far, none of the incidents has been large enough in scale to really threaten the viability of Chinese investment in the country. But this is one of the most prominent attacks to date.

Officials told the BBC's Stephen McDonell in Beijing they were confident the Pakistani government was able to manage the security situation to guarantee Chinese investment.

A female police officer, Suhai Talpur, who led the security operation during the consulate attack is being showered with praise, BBC Monitoring reports.

"Suhai Aziz, you have set an example of bravery. These are the women who are ahead of everyone," Sindh provincial chief Murad Ali Shah was quoted as saying by Pakistan Today.

"They say women belong in the kitchen. Except when everyone needs a saviour," columnist Aisha Sarwari tweeted.

Suhai Talpur joined the police force after passing the country's civil services exam in 2013, according to local media.

"When my parents decided to enrol me at a school, most of our relatives started taunting my family. So much so, that my family had to leave our village and move to a nearby town," she is quoted as telling The Express Tribune.

What is China doing in Balochistan?

By Secunder Kermani, BBC Pakistan correspondent, Islamabad

Balochistan is a sparsely populated region, and has remained Pakistan's most impoverished area despite being rich in gas and coal reserves, as well as copper and gold.

Baloch nationalists have long accused the central government of exploitation, and denying the province its due rights.

The area is at the heart of an ambitious Chinese project, the China Pakistan Economic Corridor (CPEC). The corridor is a string of huge investments by China in Pakistani infrastructure, which aim to link its western Xinjiang province with the Arabian Sea port of Gwadar in Balochistan, as part of the One Belt, One Road initiative.

China has poured billions into Pakistan, and thousands of Chinese nationals visit the country to work on CPEC projects or other business ventures. Pakistan is keen to ensure nothing happens to jeopardise that and Chinese workers are closely guarded.

The assault on the consulate is particularly significant because it took place in Karachi, the commercial capital of Pakistan, rather than in the remote province where the militants are based.

The incident will deeply concern authorities who have described the Chinese funding as a "game-changer".