"There was no intention to attack the Spanish embassy in Afghanistan... It was an attack against some guesthouses very near the embassy," he told reporters in the southeastern city of Alicante, adding one Spanish policeman had nevertheless been slightly injured.
The Taliban have claimed responsibility for the assault, which saw Kabul's Sherpur district rocked by a massive car bomb and gunfire, but it was not immediately clear if there were casualties.
But Rajoy said "it was not an attack against us," adding all employees at the embassy had been evacuated.