Law enforcement in Spain is carried out by numerous organizations, not all of which operate in the same areas.
Locally, all enforcement agencies work together closely, and in serious matters, usually under the guidance of an Examining magistrate. Operational policy and major interventions are nationally coordinated under the direction of the Ministry of the Interior.
The medieval kings of León, Castile and Aragon were often unable to maintain public peace, protective municipal leagues began to emerge in the twelfth century against bandits and other rural criminals, as well as against the lawless nobility or mobilized to support a claimant to the crown. These organizations were individually temporary, but became a long standing fixture of Spain.
The first recorded case of the formation of an hermandad occurred when the towns and the peasantry of the north united to police the pilgrim road to Santiago de Compostela in Galicia, and protect the pilgrims, a major source of regional income, against robber knights. With the countryside virtually everywhere effectively in the hands of nobles, throughout the High Middle Ages such brotherhoods were frequently formed by leagues of towns to protect the roads connecting them. The hermandades were occasionally co-opted for dynastic purposes. They acted to some extent like the Fehmic courts of Germany. Among the most powerful was the league of northern Castilian and Basque ports, the Hermandad de las Marismas: Toledo, Talavera, and Villa Real.
As one of their first acts after the War of the Castilian Succession, Ferdinand and Isabella "brought peace by the brilliant strategy of organizing rather than eliminating violence;" they established a centrally organized and efficient Holy Hermandad (Santa Hermandad) with themselves at its head. They adapted the existing form of the hermandad to the purpose of creating a general police force under the direction of officials appointed by themselves, and endowed with large powers of summary jurisdiction, even in capital cases. The rough and ready justice of the Santa Hermandades became famous for brutality. The original hermandades continued to serve as modest local police units until their final suppression in 1835.