Foreign Minister Shah Mehmood Qureshi told reporters in Islamabad that "all the terrorists have been eliminated".
"Terrorists attempted to enter Chinese consulate. Rangers and police have got control. Three terrorists killed. All Chinese safe. Situation under control," the military's media wing said in a statement.
The attack was claimed by a separatist militant group from Pakistan's southwestern province of Balochistan, which is at the centre of a major Chinese investment project in the country.
Meanwhile, Pakistani police say a powerful bomb at an open-air food market in the country's northwest has killed at least 12 people, an attack just hours after armed separatists stormed the Chinese Consulate in the southern port city of Karachi.
Local police official Tahir Ali says the market attack took place in the town of Klaya, in the Orakzai region of the Khyber Pukhtunkhwa province, which borders Afghanistan.
He said most of the victims were minority Shiite Muslims. More than 50 were wounded in the attack, some critically, triggering fears the death toll could rise further, Ali says the tragedy has prompted local authorities to declare an emergency at the region's hospitals to handle the situation.
Orakzai has been the scene of militant attacks in recent years, mostly claimed by Pakistani Sunni militants.
Pakistan's Prime Minister Imran Khan "strongly condemned" the attack on the Chinese Consulate.
Khan issued a statement, saying he has ordered a probe into Friday's attack. He described the assault as part of a conspiracy against Pakistan and China's economic and strategic cooperation.
Khan vowed in his statement that such incidents would never be able to undermine Pakistan's relations with China, which are "mightier than the Himalayas and deeper than the Arabian Sea."
Khan lauded the Karachi police and the paramilitary ranger forces, saying they showed exceptional courage in defending the consulate and that the "nation salutes the martyrs."