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.
Enforcing the law required acting as slave patrols for well over a hundred years in the US. In 1757 Georgia, for instance, the colonial assembly required white landowners to be slave patrollers, and this continued well past the civil war.
There is over a hundred years of law enforcement, particularly in the South, acting as slave patrols. It's absolutely reasonable to trace the roots from modern departments back through the nation's unique history.
Not all police followed that path, like I mentioned above, police in the North were formed more out of an interest of protecting property and landowners. Places like Boston founded their police to try and prevent crime, rather than simply exact justice post-facto. That's a different historical root of American policing, and it did not involve slave patrols.