Spain's civil protection agency said 30 litres per square metre fell in parts of the capital in just one hour, turning sections of the city's M-30 motorway into a river and flooding car parks and metro lines. Winds blowing up 90 km per hour (56 miles per hour) felled a large tree in the capital's main Retiro park as lightning lit up the city.
Some train passengers had to be evacuated in the early hours of Wednesday and lines between the capital and the southern cities of Murcia, Valencia, Almeria and Jaen remained closed.
Spain's national weather centre said rains would continue for several days in the provinces of Madrid and Castilla-La-Mancha, which civil protection has put on an orange state of alert -- the second highest level.
Spain's wetter-than-normal spring has helped alleviate drought conditions in central and southern Spain. As of Tuesday, Spain's drinking water reserves were 65 percent full but some dams in the southeast were still less than a quarter full.