The attacks threaten to derail Indian Prime Minister Narendra Modi's bold diplomatic outreach to arch-rival Pakistan following his first official visit to Afghanistan.
No group has so far claimed responsibility for the raid on the consulate in the northern Afghan city, the latest assault on an Indian installation in the country.
"We are being attacked," an Indian consulate official told AFP by telephone from inside the heavily-guarded compound.
The official, who was hunkered down in a secure area within the complex, said all consulate employees were safe and accounted for.
More From This Section
Assailants holed up in a building close to the consulate traded heavy fire with Afghan forces who cordoned off the street following a series of explosions, officials said.
"The area is completely blocked by our forces," said Shir Jan Durrani, a police spokesman in Mazar-i-Sharif, the capital of the relatively tranquil province of Balkh.
"We are cautiously conducting our clearance operation to avoid any civilian casualties."
Vikas Swarup, an Indian foreign ministry spokesman, said that no Indian casualties had been reported so far.
Seven soldiers and six attackers were confirmed killed in the assault on the Pathankot base in the northern state of Punjab, which triggered a 14-hour gun battle Saturday.
Security officials suspect the gunmen belong to the Pakistan-based Jaish-e-Mohammed, the group that staged the 2001 attack on the Indian parliament which brought the two countries to the brink of war.
The attack -- a rare targeting of an Indian military installation outside disputed Kashmir -- threatens to undermine improving relations with Pakistan.
The visit immediately followed a whirlwind tour of Kabul, where Modi inaugurated an Indian-built parliament complex and gifted three Russian-made helicopters to the Afghan government.
India has been a key supporter of Kabul's post-Taliban government, and analysts have often pointed to the threat of a "proxy war" in Afghanistan between India and Pakistan.
Pakistan -- the historic backers of the Taliban -- has often been accused of assisting the insurgents, especially with attacks on Indian targets in Afghanistan.