Sharif said that "terrorism is a common enemy of both the countries and we will fight this menace together to eliminate it once for all."
The Afghan leader "expressed his concern and grief over the incident," according to a statement by PM Office.
Ghani assured the Prime Minister "to ensure more security measures for Pakistan's diplomats in Afghanistan".
Sharif thanked the Afghani president for his concern and also conveyed his condolences on the deaths of Afghan security personnel.
Afghan officials said all three attackers and seven security forces were killed in the brazen assault in eastern Nangarhar province, where the group has made alarming inroads in recent months.