The external affairs ministry said Modi thanked Karzai for the "efforts of Afghan forces in thwarting (the) attack on India's consulate in Herat".
Modi earlier telephoned the Indian ambassador in Kabul, Amar Sinha.
Modi said in a tweet: "I condemn the attack on our consulate in Herat. Closely monitoring the situation. I have spoken to the ambassador as well."
The Indian consulate in Herat was attacked by four gunmen Friday.
Modi will be sworn in as prime minister Monday. Karzai is among the SAARC leaders expected to attend the event.