Independent Martin Surl beat Conservative Victoria Atkins after second preference as neither managed to get 50% of votes.
A total of 16% of the electorate turned out to vote in Thursday's ballot - 80,618 people.
The ex-superintendent received 27,676 of the 80,618 first preference votes. Ms Atkins received 28,422.
There was a total of 2,115 spoilt ballot papers.
When the second preference votes were counted Mr Surl was elected with a total of 36,586 votes while Ms Atkins received 32,339.
Mr Saul retired from the Gloucestershire force in January after 32 years service.
In his acceptance speech the 54-year-old acknowledged the majority of people had not voted for him but added he would remain an independent.
He said: "I will represent all those who voted for me, all those who voted for another candidate and all those who even felt the need to spoil their ballot papers [and] I can understand some of the reasons for some of that.
"I will do everything to explain what the job's about and do it to the very best of my ability."
Speaking after the count, Chief Constable Mick Matthews said the result would be the start of a "strong working relationship" between the constabulary and the commissioner.
He said: "[This will] deliver our purpose of keeping people safe from harm and inspiring the highest levels of confidence in us, their local police.
"The constabulary is committed to working positively with the PCC in the future to ensure the focus remains upon delivering a police force that best serves our communities in Gloucestershire."
A former senior police officer has been chosen as Gloucestershire's police and crime commissioner (PCC).