The attack on the site was carried out in retaliation for the arrest of three Spanish men the police claimed were ‘core’ members of the group.
The hackers managed to keep www.policia.es offline for about an hour from 2130 GMT on 12 June.
Spanish authorities would not confirm that Anonymous was behind the attack, saying only that the site was offline.
However, a statement was posted on a website linked to Anonymous, claimed responsibility for the hack, which it called #OpPolicia.
The group said it had used a distributed denial of service attack (DDoS) which bombards a target website with so much data that it becomes overwhelmed.
A spokesman for the Spanish police said the cause of the outage had not yet been established.
“A website can collapse if too many people try to access it at once. I cannot confirm the link with the Anonymous group,” said the spokesman.
In its statement, Anonymous said the DDoS attack was a “direct response to the Friday arrests of three individuals alleged to be associated with acts of cyber civil disobedience attributed to Anonymous.”
The group said DDoS attacks were a legitimate form of peaceful protest. Some of its members are thought to have carried out similar attacks on Turkish government websites to protest against net censorship.