Armed separatists stormed the Chinese Consulate in Pakistan's southern port city of Karachi on Friday, triggering an intense hour-long shootout during which two Pakistani civilians, two police officers and all three assailants were killed, Pakistani officials said.

The killed Pakistani civilians were a father and a son had come to the consulate to pick up their visas to China, police said.

The brazen assault, claimed by a militant group from the southwestern province of Baluchistan, reflected the separatists' attempt to strike at the heart of Pakistan's close ties with major ally China, which has invested heavily into road and transportation projects in the country, including in Baluchistan.

SHAKIL ADIL/AP Pakistani security personnel arrive at the Chinese Consulate in Karachi, Pakistan.

All the Chinese diplomats and staff at the consulate were safe and were not harmed during the attack or the shootout, senior police official Ameer Ahmad Sheikh said. They were evacuated from the area shortly after and taken to a safe place.

READ MORE:

* Overturned oil tanker explodes, killing 153 in Pakistan

* 10 wounded in explosion in Turkish city

* Gunmen kill 20 before Bangladesh commandos end siege

* 15 dead after Somali Islamist militants attack hotel

* Philippine troops clash with Muslim rebels

Following the attack, China asked Pakistan to beef up security at the mission. In Beijing, Foreign Ministry spokesman Geng Shuang said that China would not waver in its latest big project in Pakistan - the China-Pakistan Economic Corridor - and expressed confidence that Pakistan could ensure security.

SHAKIL ADIL/AP Pakistani security personnel stand guard at an entrance of the Chinese Consulate in Karachi.

Pakistani Prime Minister Imran Khan condemned the attack, describing it as part of a conspiracy against Pakistan and China's economic and strategic cooperation. Khan lauded the Karachi police and the paramilitary rangers, saying they showed exceptional courage in defending the consulate and that the "nation salutes the martyrs".

He also ordered an investigation and vowed that such incidents would never be able to undermine relations with China, which are "mightier than the Himalayas and deeper than the Arabian Sea".

The attackers stormed the consulate shortly after 9am (local time), during business hours. They first opened fire at consulate guards and hurled grenades, then managed to breach the main gate and enter the building, said Mohammad Ashfaq, a local police chief.

SHAKIL ADIL/AP Pakistani troops move in the compound of the Chinese Consulate in Karachi, Pakistan.

Pakistani security forces quickly surrounded the area. Local TV broadcast images showing smoke rising from the building, which also serves as the residence of Chinese diplomats and other staff.

Multiple blasts were heard soon afterward but Sheikh could not say what they were. The shootout lasted for about an hour.

"Because of a quick response of the guards and police, the terrorists could not" reach the diplomats, Sheikh said after the fighting ended. "We have completed the operation."

SHAKIL ADIL/AP Pakistani security forces quickly surrounded the area after an attack at the Chinese Consulate.

He added that one of the attackers was wearing a suicide vest and that authorities would try and identify the assailants through fingerprints. Dr Seemi Jamali, a spokeswoman at the Jinnah Hospital, said a consulate guards was also wounded in the attack and was being treated at the hospital.

Geng, the Chinese spokesman, said the attackers hadn't managed to get into the consulate itself, and that the exchange of fire took place outside the building. The discrepancy with the Pakistani officials' reports could not be immediately reconciled.

Elsewhere in Pakistan on Friday, a powerful bomb at an open-air food market in the Orakzai region of the Khyber Pukhtunkhwa province, which borders Afghanistan, killed 25 people and wounded dozens of others, said police official Tahir Ali.

Most of the victims in the attack in the town of Klaya were minority Shiite Muslims. No one immediately claimed responsibility for the bombing. Orakzai has been the scene of several militant attacks in recent years, mostly by Pakistani Sunni militants, who revile Shiites as apostates.

In its claim of responsibility for the Karachi attack, the Baluch Liberation Army said it was fighting"Chinese occupation" and released photos of the three attackers.

This was the second attack this year by Baluch separatists in Pakistan. Karachi, the capital of Sindh province, which borders Baluchistan, has a presence of several militant groups, including Baluch separatists.

In August, a suicide bomber rammed into a bus ferrying Chinese workers to the Saindak mining project in southwestern Baluchistan, wounding five workers. The project is controlled by the Chinese state-owned Metallurgical Corporation of China. And in May, gunmen opened fire on two Chinese nationals in Karachi, killing one and wounding the other.

Friday's attack was an uptick in the level of violence perpetrated by the Baluch separatist, said Amir Rana, executive director of the independent Pakistan Institute for Peace Studies.

So far this year, the Baluch Liberation Army has claimed responsibility for 12 attacks against security personnel guarding projects linked to the so-called Chinese Pakistan Economic Corridor as well as to the infrastructure.

In a letter dated August 15, the group released a letter warning China against the "exploitation of Baluchistan's mineral wealth and occupation of Baluch territory". The letter was addressed to China's ambassador to Pakistan.

But, Rana said, both China and Pakistan have calculated the security risks, which include the threats from the Baluch separatist.

"I don't see that this will have any impact on the Chinese projects in Pakistan. These threats were already on Pakistan and China's threat radar," he said.

The attack will compel China to step-up security around its people in Pakistan and increase cooperation with the local authorities, said Zhao Gancheng of the Shanghai Institute of Foreign Studies. But he said that would not sway China's government and Chinese firms from expanding their footprint abroad, even while they take additional precautions.

"As more and more Chinese people go abroad, and more and more Chinese investment goes overseas, the security situation of the destination countries has become a very important element for consideration," Zhao told The Associated Press.

China is a longtime ally and has invested heavily in transport projects in Pakistan. The two countries have strengthened ties in recent years and China is currently building a network of roads and power plants under a project known as the China-Pakistan Economic Corridor, or CPEC.

The Baluchistan separatists have for years fought a low level insurgency in Pakistan, demanding a greater share of the province's wealth and natural resources

In a rare statement about attacks in Pakistan, neighbouring India condemned the assault on the Chinese Consulate, saying that "there can be no justification whatsoever for any act of terrorism".

New Delhi also said "perpetrators of this heinous attack should be brought to justice expeditiously".

Pakistan has long accused India of supporting Baluch separatists. The two countries have a history of bitter relations and have fought two of their three wars over the disputed region of Kashmir since gaining independence from Britain in 1947.