The decision follows similar moves in France and Portugal and obliges judges to consider pets as sentient beings rather than objects owned by one or the other partner, a trend that was already underway before the law was passed.
"Animals are part of the family and when a family decides to separate, the fate of the animal must be regulated with the same importance as the fate of other family members," said lawyer Lola Garcia, 42.
In October, a Madrid judge gave joint custody of a dog to an unmarried couple who sought a court ruling on whom the pet should stay with after they separated. The dog spends a month with each of them and both are legally responsible.
Garcia, whose Rights&Animals firm handled the case, considers the reform a major first step in a series of forthcoming legal changes governing people's relationship with animals.
Pet ownership is high in Spain among European countries and the left-wing coalition government plans further legislation to strengthen animal rights, including a ban on wild animals in circuses and stopping the sale of pets in shops.
However, the nation remains polarized around the tradition of bullfighting, a hotly contested animal rights issue that is unlikely to be resolved in the near future.
Previously, a lawyer seeking joint custody of a pet had to prove both members of a couple owned the animal as an object, giving whoever had registered the pet an advantage.
Now a judge has to determine where the animal will fare better and that determination is based on the animal's well-being, Garcia explained.
A partner that can demonstrate financial solvency or who has been granted custody of their children has a better chance of securing custody of any pets too, as there is a special affective link between children and animals, she added.
Rodrigo Costavilas, 31, a psychologist out walking his dog in the Madrid Rio park, praised the new law.
"This will help in the reduction of animals being abandoned or badly treated."