The new measure came after a Spanish doctor was convicted last week in a major blood-doping scandal on public health charges. Education and Sports minister Jose Ignacio Wert told parliament the law would bring Spain's laws into line with World Anti-Doping Agency requirements.
According to a draft of the law, it raises fines for doping to up to €400,000 but stops short of making doping punishable by jail.
It strengthens the role of Spain's national anti-doping authority and gives inspectors the right to carry out doping tests on sportsmen overnight in certain cases.
Wert said the tougher rules are "an indispensable condition" for Madrid's candidacy for the 2020 summer Olympics and Barcelona's bid for the winter games in 2022.
Passed on Thursday by a large majority in the lower house of parliament, the bill must now go to the Senate for approval.
It is expected to be definitively adopted by the lower house before the host of the 2020 Olympics is named on September 7th.
"We have bet on these candidacies and we have to be consistent, putting in place all the necessary measures to succeed in them," including "an anti-doping law that satisfies international requirements," Wert said.
He said the new law puts an emphasis on protecting athletes' health but also shakes up the sanctions process, creating a new Sports Administrative Court.
A Madrid court on April 30 sentenced doctor Eufemiano Fuentes, 57, to a year in prison for endangering public health by performing blood transfusions on top cyclists.
The judge refused however to release to sporting authorities bags of blood seized from Fuentes which could identify other sportsmen he treated.
The case, dubbed Operation Puerto, was judged on public health charges because doping was not a crime in Spain until 2006. Spain's current doping law was introduced that year shortly after the Puerto affair erupted.
Wert in parliament on Thursday voiced his "deep disagreement" with the sentence, "which by only convicting the doctor prevents the cheaters from being known and sanctioned in the sporting sphere".