Law enforcement is the activity of some members of government who act in an organized manner to enforce the law by discovering, deterring, rehabilitating, or punishing people who violate the rules and norms governing that society. The term encompasses police, courts, and corrections. These three components may operate independently of each other or collectively through the use of record sharing and cooperation. Throughout the world, law enforcement are also associated with protecting the public, life, property, and keeping the peace in society. 
The concept of law enforcement dates back to ancient times, and forms of law enforcement and police have existed in various forms across many human societies. Modern state legal codes use the term law enforcement officer or peace officer to include every person vested by the legislating state with police power or authority; traditionally, anyone sworn or badged who can arrest any person for a violation of criminal law is included under the umbrella term of law enforcement.
Although law enforcement may be most concerned with the prevention and punishment of crimes, organizations exist to discourage a wide variety of non-criminal violations of rules and norms, effected through the imposition of less severe consequences such as probation.
Law enforcement organizations existed in ancient times, such as prefects in ancient China, paqūdus in Babylonia, curaca in the Inca Empire, vigiles in the Roman Empire, and Medjay in ancient Egypt. Who law enforcers were and reported to depended on the civilization and often changed over time, but they were typically enslaved people, soldiers, officers of a judge, or hired by settlements and households. Aside from their duties to enforce laws, many ancient law enforcers also served as slave catchers, firefighters, watchmen, city guards, and bodyguards.
By the post-classical period and the Middle Ages, forces such as the Santa Hermandades, the shurta, and the Maréchaussée provided services ranging from law enforcement and personal protection to customs enforcement and waste collection. In England, a complex law enforcement system emerged, where tithings, groups of ten families, were responsible for ensuring good behavior and apprehending criminals; groups of ten tithings ("hundreds") were overseen by a reeve; hundreds were governed by administrative divisions known as shires; and shires were overseen by shire-reeves. In feudal Japan, samurai were responsible for enforcing laws.
The concept of police as the primary law enforcement organization originated in Europe in the early modern period; the first statutory police force was the High Constables of Edinburgh in 1611, while the first organized police force was the Paris lieutenant général de police in 1667. Until the 18th century, law enforcement in England was mostly the responsibility of private citizens and thief-takers, albeit also including constables and watchmen. This system gradually shifted to government control following the 1749 establishment of the London Bow Street Runners, the first formal police force in Britain. In 1800, Napoleon reorganized French law enforcement to form the Paris Police Prefecture; the British government passed the Glasgow Police Act, establishing the City of Glasgow Police; and the Thames River Police was formed in England to combat theft on the River Thames. In September 1829, Robert Peel merged the Bow Street Runners and the Thames River Police to form the Metropolitan Police. The title of the "first modern police force" has still been claimed by the modern successors to these organizations.
Following European colonization of the Americas, the first law enforcement agencies in the Thirteen Colonies were the New York Sheriff's Office and the Albany County Sheriff's Department, both formed in the 1660s in the Province of New York. The Province of Carolina established slave-catcher patrols in the 1700s, and by 1785, the Charleston Guard and Watch was reported to have the duties and organization of a modern police force. The first municipal police department in the United States was the Philadelphia Police Department, while the first American state police, federal law enforcement agency was the United States Marshals Service, both formed in 1789. In the American frontier, law enforcement was the responsibility of county sheriffs, rangers, constables, and marshals. The first law enforcement agency in Canada was the Royal Newfoundland Constabulary, established in 1729, while the first Canadian national law enforcement agency was the Dominion Police, established in 1868.
By the late modern period, improvements in technology, greater global connections, and changes in the sociopolitical order led to the establishment of police forces worldwide. National, regional, and municipal civilian law enforcement agencies exist in practically all countries; to promote their international cooperation, the International Criminal Police Organization, also known as Interpol, was formed in September 1923. Technology has made an immense impact on law enforcement, leading to the development and regular use of police cars, police radio systems, police aviation, police tactical units, and police body cameras.
For a more comprehensive list, see List of law enforcement agencies.
Most law enforcement is conducted by some law enforcement agency, typically a police force. Civilians generally staff police agencies, which are typically not a military branch. However, some militaries do have branches that enforce laws among the civilian populace, often called gendarmerie, security forces, or internal troops. Social investment in enforcement through such organizations can be massive in terms of the resources invested in the activity and the number of people professionally engaged to perform those functions.
Law enforcement agencies are limited to operating within a specified jurisdiction. These are typically organized into three basic levels: national, regional, and municipal. However, depending on certain factors, there may be more or less levels, or they may be merged: in the United States, there are federal, state, and local police and sheriff agencies; in Canada, some territories may only have national-level law enforcement, while some provinces have national, provincial, and municipal; in Japan, there is a national police agency, which supervises the police agencies for each individual prefecture; and in Niger, there is a national police for urban areas and a gendarmerie for rural areas, both technically national-level. In some cases, there may be multiple agencies at the same level but with different focuses: for example, in the United States, the Drug Enforcement Administration and the Bureau of Alcohol, Tobacco, Firearms and Explosives are both national-level federal law enforcement agencies, but the DEA focuses on narcotics crimes, while the ATF focuses on weapon regulation violations.
Various segments of society may have their own specialist law enforcement agency, such as the military having military police, schools having school police or campus police, or airports having airport police. Private police may exist in some jurisdictions, often to provide dedicated law enforcement for privately-owned property or infrastructure, such as railroad police for private railways or hospital police for privately-owned hospital campuses.
Depending on various factors, such as whether an agency is autonomous or dependent on other organizations for its operations, the governing body that funds and oversees the agency may decide to dissolve or consolidate its operations. Dissolution of an agency may occur when the governing body or the agent itself decides to end operations. This can occur due to multiple reasons, including criminal justice reform, a lack of population in the jurisdiction, mass resignations, efforts to deter corruption, or the governing body contracting with a different agency that renders the original agency redundant or obsolete. According to the International Association of Chiefs of Police, agency consolidation can occur to improve efficiency, consolidate resources, or when forming a new type of government.