The Spanish Congress on Thursday passed the law, which will put Spain in line with the 1987 European Convention for the Protection of Pet Animals.
Prime Minister Mariano Rajoy's conservative People's Party (PP) had voted against the legislation, while the liberal Ciudadanos and Basque Nationalist Party (PNV) abstained, according to El Pais.
“I am sure that when those of you who have dogs go home, it is one of the best moments of your day, and I'm sure that you know how delightful it is when your dog comes to greet you,” said the leader of the left-wing Podemos party, Pablo Iglesias.
Then referring to Rajoy's own dog, Rico, Iglesias said: “I am sure that he loves him just as much as we all love our animals.”
The practice of removing parts of a dog's tail, known as docking, is often justified by hunters as a way to prevent their pet from collecting burrs or brambles that could cause them pain or infection.
But opponents say it causes the dog unnecessary pain and suffering, and when performed incorrectly, the procedure can lead to lifelong problems.
“Cutting the tail due to the owner's own whims is cruelty,” said Zaida Cantera from the social-democratic PSOE party.
Guillermo Díaz of Ciudadanos said that whoever would “torture or harm” an animal “in an unnecessary way is in many ways a danger to society.”
“How many sociopaths have started by torturing animals?”
The PP had objected to the law, saying the practice should be allowed for hunters while dogs are still puppies.
The new law will still allow veterinarians to decide whether there is a medical reason for docking.
Before the new national legislation, a number of local authorities had already banned docking, including Madrid and Andalusia. But hunters would sometimes then cross over to other regions where the operation was not illegal.