Across the city, people are swapping tales of night-time battles to swat moths lured by the light into their bedrooms, a whole new genre of jokes has been born and the phenomenon has become a trending Twitter topic.
No-one is sure of precisely where they came from.
Roger Vila, researcher at the butterfly diversity and evolution laboratory in the northeastern city of Barcelona, identified three types of moth from photographic evidence: the Gamma, Noctua and Catocala.
Many of them flew to the capital from southern Spain but others may have migrated from northern Africa on a long journey across the Gibraltar Strait to destinations across Europe, he told AFP on Monday.
"What happened is that there were very special climactic conditions," Vila explained.
After a cool, rainy spring ideal for the vegetation that caterpillars feed on, the weather turned hot recently, leading the moths to emerge en masse from their chrysalids at about the same time, the scientist said.
The flying insects, which carry no health risk and are not the clothes-eating variety, probably ended up in Madrid because of prevailing winds, Vila said.
"They live for about a week so they will certainly die within a few days," he added. "The only question is whether more arrive at some point."
Jose Maria Camera, a vet at the Madrid city hall's health department, said there were countless moths in the city.
Residents had called the city authorities with sightings of anything from two or three moths to a barely credible 150, he said.
"The first reaction was alarm, then curiosity and even irony and jokes," the city official said.
Many citizens, for example, jokingly blame Atletico Madrid football supporters, who won this year's Spanish Cup and removed their scarves from musty drawers for the supposedly rare celebration.
On Twitter, one wit is sending messages pretending to be a moth (polilla in Spanish) and signing them Polilla de Madrid. One of his latest tweets reads: "The truth is your homes are so comfy. Don't you love the sound of our wings?"