Law enforcement in Spain is carried out by numerous organizations, with different duties and jurisdictions. Police officers in Spain are permanent public servants, who uphold public safety and compliance of the law. Being a law enforcement officer in Spain is not only a job, but rather a legal condition ("agents from the authority"), as they are legally obligated to intervene in all situations they witness "in defense of the law and public safety" regardless of them being on or off duty.

Police forces in Spain are armed.

Types of police forces In Spain, different police forces operate on the national, autonomous and local level.

National forces The law enforcement bodies that operate in most of the national territory, under the Ministry of the Interior, are: (National Police Corps) is the civilian police force with the duties of urban areas policing, judicial investigations, documentation expedition and immigration enforcement. It is formed by about 73.000 officers. (Civil Guard) is the national gendarmerie force responsible for rural areas policing, firearms and explosives control; traffic policing on intercity roads; protection of coasts, borders, ports, and airports; enforcement of environmental and conservation laws, including those governing hunting and fishing; and intercity transport of prisoners. During wartime, it depends from the Ministry of Defense. It has also operated as military police in support of the Spanish Armed Forces on peace-keeping deployments. It is formed by about 81.500 officers.

Autonomous forces As Spain is divided in autonomous communities, some have acquired policing duties over time. The autonomous communities that have their own police forces take over on most duties of the national-level forces. These are: Autonomous CommunityForce nameOfficersNotes6,865Has replaced the national forces in most duties.19,029Has replaced the national forces in most duties.1,116Still shares some duties with the national forces.286Not an integral police force, shares duties with the national forces. They answer to their respective autonomous governments interior/public safety departments.

Other autonomous communities that do not have their own forces may have shared units with the National Police () that carry out building protection, VIP escorts, control of gambling installations and other small duties. Currently Andalusia, Valencian Community, Galicia and Aragon have active shared units.

Local forces Every municipality in Spain with a population of at least 5.000 is allowed to have a local police force. Their duties are mostly based on cooperation in public safety with the national or autonomous force and traffic enforcement and investigation.

They can be known as , or depending on their historic background.

Other Spain has other police forces that carry out specific duties, such as:

(Customs Surveillance Service) is in charge of customs inspections, smuggling investigations, tax evasion, and illegal financial transactions, particularly those involving import-export businesses and currency exchange (mostly in cooperation of the National Police and the Civil Guard). Most of its officers are stationed at border crossing points with France, Andorra, and Portugal. (Port Polices) are forces dependent on each maritime port authority that provide uniformed policing duties related to public safety in loading and unloading of vessels, storage of cargo and traffic enforcement within portuary areas. (Rural agents) are forces dependent on autonomous communities that control hunting activities and prevent visitors from gathering or damaging wild plants, dumping rubbish, starting fires or behaving irresponsibly in addition to providing routine surveillance and fire extinction services via regular surface and airborne patrols as well as from fixed towers and strategic installations. Even though Guardia Civil has a military aspect, military bases and installations policing is carried out by military forces. (Military Police) for Army bases. (Naval Police) for Navy and Marines bases. (Aerial Police) for Air and Space Force bases. Even though there are several different police forces in Spain, they usually cooperate in the exercice of their duties and investigations. The National Intelligence Centre also cooperates with police forces providing both foreign and domestic intelligence.

History The medieval kings of León, Castile, and Aragón 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 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 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 : 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 () with themselves at its head. They adapted the existing form of the 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 became famous for brutality. The original continued to serve as modest local police units until their final suppression in 1835.

20th century

The principal forces of public order and security as of 1988 were the Civil Guard, founded in 1844, and the National Police Corps, founded in 1986. The Civil Guard, fortified by nearly a century and a half of tradition, was a highly disciplined paramilitary body with close links to the Spanish army. As it evolved, it served mainly as rural police to protect property and order and to reinforce the authority of the central government.

Under Francisco Franco, a tripartite system of police was formalized: the Civil Guard in rural areas; the Armed and Traffic Police (renamed the National Police in 1979), which fulfilled normal police functions in communities with a population of more than 20,000; and the Higher Police Corps of plainclothes police with responsibility for investigating crimes and political offenses. Separate municipal police forces under the control of local mayors were concerned mainly with traffic control and with enforcement of local ordinances.

The transition from Franco's dictatorship to a system of parliamentary democracy was accompanied by a major effort to bring the forces of law and order and the justice system into harmony with the new political era. The police were stripped of most of their military characteristics. The Civil Guard, which maintained order in rural areas and in smaller communities, retained many of its military features, but both the Civil Guard and the police were placed under civilian leadership.

Once dedicated to repressing all evidence of opposition to the Franco regime, the police and the Civil Guard were expected to tolerate forms of conduct previously banned and to protect individual rights conferred by the 1978 Constitution and by subsequent legislation. Members of the Civil Guard continued to be implicated in cases of mistreatment and brutality in the campaign against Basque terrorism. The authorities had, however, prosecuted many civil guard officers for such infractions, with the result that by 1988 fewer violations of legal norms were being recorded.

Reforms of the judicial system included appointments of judges by a body insulated from political pressures and increased budgets to enable courts to deal with a chronic backlog of criminal hearings. The penal code was being modernized to bring it into conformity with the new Constitution. Some progress had been made in ensuring that defendants had effective legal representation and that they received speedier trials. Nevertheless, antiquated procedures and the escalation of crime continued to generate huge delays in the administration of justice, with the result that as much as half of the prison population in 1986 consisted of accused persons still awaiting trial.

During the Franco era, the police had been regarded as a reactionary element, associated in the public mind with internal surveillance and political repression. The Civil Guard and the Armed and Traffic Police were legally part of the armed forces, and their senior officers were drawn from the army. The 1978 Constitution effects the separation of the police from the military, and it emphasizes that one of the functions of the police is to safeguard personal liberties. Article 104 of the 1978 Constitution states that, "The Security Corps and Forces, responsible to the Government, shall have as their mission the protection of the free exercise of rights and liberties and the guaranteeing of the safety of citizens."

Although considerably delayed, a subsequent statute, the Organic Law on the Security Corps and Forces, was enacted in March 1986 to incorporate the mandate of the Constitution to redefine the functions and the operating principles of the police forces. With its passage, the final legal steps had been taken to make the police system conform to the requirements of the democratic regime, although most observers concluded that it would be years before the reforms were fully in effect.

The new organic law provided a common ethical code for police practices, affirmed trade union rights, recast the role of the judicial police serving under the courts and the public prosecutors, combined the uniformed and the non-uniformed police into the single National Police Corps, and redefined the missions and the chains of command of the various police bodies. The Civil Guard remained a separate paramilitary force, although in operational matters it was under the direction of the Ministry of Interior rather than the Ministry of Defence.

In time of war or emergency, it would revert to the authority of the minister of defence. In 1986 a new post of secretary of state for security was created in the Ministry of Interior to coordinate the activities of the National Police Corps and the Civil Guard. The National Police Corps functioned under the directives of the director-general of the National Police Corps, but local supervision was exercised by civil governors of the provinces where police forces served.

Although their powers were, in most cases, quite limited, the local police services of individual towns and cities complemented the work of the National Police Corps, dealing with such matters as traffic, parking, monitoring public demonstrations, guarding municipal buildings, and enforcing local ordinances. They also collaborated with the National Police Corps by providing personnel to assist in crowd control. Numbering about 37,000 individuals in 1986, the local police were generally armed only with pistols, although many smaller local police forces, particularly in Guipúzcoa, have continued to maintain an unarmed policing tradition, although this has met legal challenges recently and Eibar is set to have a fully armed local police force in 2020, with the 40 remaining unarmed police forces in the province likely to follow.