Landowners and merchants hired private police to watch over their holdings. Over time, they convinced locals that it would be in the public good if the guards they hired were paid for by everyone.
In the 1850s, in Boston, they formalized this arrangement into the first police department in the country. (There's an interesting history here around the oppression and then incorporation of Boston's Irish population by the police force.)
Edit: Curious about the downvotes -- this is a review of US history.
The first American police dept was founded in the 1850s, well after the split from England. The first police department in England was founded in the 1830s.
Prior to that, our communities either took collective action to regulate themselves and the 'spirit of the community', insisted on night watch duty as a rotating responsibility, paid a constable or sheriff (a word whose roots are 'shire reeve', meaning 'shire official'), or hired private guards to protect property.
In the 1850s, around the time of the first police departments in the US, the Fugitive Slave Act was enforced as law -- requiring officials to hunt and 'return' runaway slaves. This was adopted to a greater or lesser degree depending on the area, but it absolutely was a role of law enforcement across much of the US, and it's without a doubt a part of the roots of many police departments in the US.
The very simple historical trend that brought us the police we have today started with the King enforcing the peace, was delegated to sheriffs who enforced the peace among other things, was inherited in the colonies where the sheriff took on a primarily peace officer role in early states, and as the population grew and cities got bigger were augmented with more specialized and local peace officers. Slave patrols being the root of police is just propaganda.