The canisters did not explode and there were no injuries, a police spokeswoman told AFP.
The man, who was arrested, "was a business owner, who had lost everything", she added.
Police initially said the car contained an explosive device that did not explode, but later ruled that out.
Another police spokeswoman said they had instead found an unidentified substance that had yet to be analysed.
She would not confirm media reports that the car contained industrial fertiliser.
More From This Section
Police cordoned off a large area around the Popular Party (PP) building in central Madrid, causing long traffic tailbacks and blocking people from getting to work.
Several metro stations were closed and service on one line was suspended.
The party's parliamentary spokesman Rafael Hernando ruled out the attack being the work of Islamists but expressed concern that someone would "attack a political party -- mine or any other."
Spain is fighting to recover from a six-year economic crisis that left it with a current unemployment rate of nearly 24 percent.
Hernando said Prime Minister Mariano Rajoy's government was "working to change things".