A county sheriff and his deputies, when authorized by written agreement entered into by the sheriff and a city, town or village within the county and approved by the governing body of the county, shall have the same power and authority to enforce the ordinances of the city, town or village, and in the same manner, as have the police of the city, town or village.