A trusted officer crossed a line at work and again when out with colleagues - he narrowly avoided being locked in prison.