KABUL—Taliban militants on Friday night attempted to storm a Spanish embassy compound here, killing a Spanish security official and wounding 10 other people in the latest high-profile attack by the group following government efforts to revive peace talks aimed at ending the insurgency.

The attack started with a car bomb that detonated close to the compound’s gates, causing an explosion that shook buildings across the diplomatic district in the city center, shattering nearby windows. A Spanish embassy official said the blast...