Eugene Francois Vidocq was a criminal. Well, kind of. He was in military, and he fled after killing two officers.
He spent years commiting fraud, forgery, privateering and was finally arrested in 1809. During his time in prison, he offered help to the police, an offer which they accepted. He spent most of his time walking around the prisons, gathering intel from other prisoners.
In 1883, Vidocq made his own detective agency! He personally trained his agents, for example, in selecting the right disguises based on the kind of job.
So that was the story of the world’s first known detective!