KABUL, Afghanistan — Even before he received specific intelligence about an attempt planned on his life, Amrullah Saleh had a feeling they were coming for him soon. So he wrote his will.

As a former Afghan intelligence chief who is staunchly anti-Taliban, he had been near the top of the militants’ list for a long time. But now there was an added reason for targeting him: He was about to launch his campaign as the running-mate of President Ashraf Ghani in his September re-election bid.

About a week ago, Mr. Saleh took a new look at the four-page will. He added instructions for his wife and five children on how to handle news of his death, and how to gain access to his savings.

Mr. Saleh said he was convinced that “I wasn’t going to survive this time.”

The attack he dreaded came on Sunday, the first day of the presidential campaign, after he and President Ghani had appeared at a tightly guarded rally in Kabul, Afghanistan’s capital.