Tourists and local residents lined the streets to watch as the bleating, bell-clanking parade passed the Spanish capital's most emblematic locations, cutting traffic.
The herd was accompanied by musicians and dancers dressed in regional costumes that have been worn by rural workers for centuries.
Shepherds halted at the town hall so the chief herdsman could hand local authorities 50 “maravedies” — copper coins first minted in the 11th century — as payment for the crossing.
The parade started in the Casa de Campo, a former royal hunting ground that is now Madrid's largest park, then made its way through the Puerta del Sol — the main square — and past the Bank of Spain's headquarters before ending up at the town hall.
Every year since 1994 sheep farmers have paraded their livestock through the city along a route that once cut through undeveloped countryside on their way to winter grazing pastures in southern Spain.
Since medieval times, shepherds have had the right to use herding paths crisscrossing a landscape that was once woodland and grazing space.