Gunmen stormed the Chinese consulate in Pakistan's port city of Karachi on Friday, killing at least two policeman in an attack claimed by a militant group in Balochistan province.
Karachi's police chief said three attackers arrived at the consulate in a car filled with explosives but were killed in a shootout before they could enter.
"They could not even get in the compound. They tried to get into the visa section," Amir Shaikh said.
Pictures posted to social media purportedly of the attack showed smoke rising from the area.
The attack was claimed by Balochistan Liberation Army (BLA), a separatist militant group in the Pakistan's south-western province which is at the centre of a major Chinese investment project in the country.
"We have carried out this attack and our action is continuing," a spokesman for the group, Geand Baloch, said.
"We have been seeing the Chinese as an oppressor, along with Pakistani forces," he said, adding they were "destroying the future of Balochistan".
The group had claimed an attack in August in which five people including two Chinese citizens were injured when a truck loaded with explosives detonated as a bus carrying Chinese engineers was passing on a road in the Dalbandin region of Balochistan.
The BLA is just one of the militant groups operating in Balochistan, Pakistan's largest and poorest province, which is rife with ethnic, sectarian and separatist insurgencies.
Pakistan's foreign minister Shah Mahmood Qureshi said all the diplomats and staff at the consulate had been taken to a safe place.
He told reporters in the capital, Islamabad, that the attack was a "conspiracy" against Pakistan and China and blamed an "enemy of Pakistan".
Prime Minister Imran Khan ordered an inquiry into the incident, according to a statement released by his office.
"Such incidents will never be able to undermine Pak-China relationship," the statement said, describing the attack as part of a conspiracy aimed at undermining economic and strategic co-operation between the two nations.
The attack was immediately condemned by India, which has a decades-old rivalry with Pakistan and is competing with China for influence in the region.
Mr Khan said on Twitter that the attack on the consulate and a deadly bombing hours later at a market in north-west Pakistan were attempts to scare away Chinese investors and undermine trade deals reached during his visit to China this month.
China, one of Pakistan's closest allies, has poured billions into the country in recent years as part of a massive infrastructure project that seeks to connect its western province of Xinjiang with the Arabian Sea port of Gwadar.
The project, the China-Pakistan Economic Corridor (CPEC), is one of the largest projects in Beijing's "One Belt One Road" initiative, comprising a network of roads and sea routes involving 65 countries.
But for Pakistan, participating in the project presents an enormous challenge in a country plagued by weak institutions, endemic corruption and a range of insurgencies in areas along the corridor.
The subject of economic dividends from CPEC is extremely sensitive in some of the areas the corridor will run through - particularly in resource-rich Balochistan.
Since the beginning of the project militants have repeatedly attacked construction sites and targeted Chinese workers.
Karachi, the capital of Sindh province and Pakistan's largest city and a financial hub, was for years rife with political, sectarian and ethnic militancy.
A crackdown in the city by security forces in recent years has brought a lull in violence, but scattered attacks still take place.
Pakistan at 'low point', Imran Khan tells China's Xi
Baloch insurgents claim Pakistan bombing against Chinese mineral workers
Belt and Road Initiative: China's global development strategies have changed the rules of the game