Gunmen have attacked the Chinese consulate building in Karachi, Pakistan, killing two civilians, two policemen and injuring a security guard.

The civilians were a father and son visiting the consulate to pick up visas for China, police said, adding that all three of the gunmen were killed by security forces in a gun battle that lasted about an hour.

Smoke was seen rising from the building and pictures of the aftermath showed two burnt-out vehicles at the front gate, which was itself badly damaged.

There were conflicting reports about how far into the compound the gunmen managed to reach, though no Chinese diplomats or officials were injured in the attack.

The attack has been claimed by the insurgent Balochistan Liberation Army, a militant group which seeks self-determination for the Baloch people in Pakistan. A spokesperson for the group told Al Jazeera that three of its “fidayeen” – meaning “those who sacrifice themselves” – had carried out the attack armed with guns and grenades.

Two police officers killed after gunmen storm Karachi Chinese consulate

Police said at least one of the attackers was wearing a suicide vest, and that a vehicle laden with explosives was also used.

Mohammad Ashfaq, a local police chief, said the attackers first opened fire on consulate guards and then hurled grenades, shortly after the consulate had opened for business.

He said the gunmen managed to breach the main gate and enter the building.

“Because of a quick response of the guards and police, the terrorists could not” reach the diplomats, senior police official Ameer Ahmad Sheikh said after the fighting was over. “We have completed the operation.”

In Beijing, foreign ministry spokesperson Geng Shuang said the attackers hadn’t managed to get into the consulate itself, and that the exchange of fire took place outside the building. It wasn’t clear what led to the discrepancy between his account and that of local police.

The brazen attack reflects attempts to drive a wedge between the Pakistan government and its major ally China. The Reuters news agency quoted a spokesman for the Balochistan Liberation Army that accused China of “exploiting our resources”.

China has funded development of a number of major projects, including a deepwater port, in Balochistan. The province is Pakistan's poorest but has rich mineral and natural gas reserves.

The prime minister, Imran Khan, ordered an immediate inquiry into the attack, calling it “part of conspiracy against Pakistan and China economic and strategic cooperation”.

The Chinese government’s top diplomat, Wang Yi, said he was “shocked” by the incident and urged Pakistan to prevent any more attacks.

Support free-thinking journalism and attend Independent events

Nonetheless when Mr Geng was asked if the attack would affect Chinese investment in Pakistan, he said China would “continue unswervingly” to work with Pakistan to develop joint projects.

Elsewhere in Pakistan on Friday, a powerful bomb at a market in the Orakzai region of the Khyber Pakhtunkhwa province, which borders Afghanistan, killed 35 people and wounded at least 50.