KARACHI, Pakistan — Armed separatists stormed the Chinese Consulate in Pakistan's southern port city of Karachi on Friday, triggering an intense hour-long shootout.

Two Pakistani civilians, two police officers and all three assailants were killed, according to Pakistani officials.

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

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.

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 major project in Pakistan — the China-Pakistan Economic Corridor — and expressed confidence that Pakistan could ensure security.

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 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 9 a.m., 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.

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."

He added that one of the attackers was wearing a suicide vest and that authorities would try and identify the assailants through fingerprints.

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

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 Aug. 15, the group released a letter warning China against the "exploitation of Baluchistan's mineral wealth and occupation of Baloch territory." The letter was addressed to China's ambassador to Pakistan.

The Baluchistan separatists have fought a low-level insurgency in Pakistan for years.