McGinn begged the officers who arrested him to dispose of the cocaine
A police officer dealt cocaine while on secondment to his force's drugs unit, a court has heard.
Christopher McGinn was caught with the drug in a pub car park, by colleagues from Lothian and Borders Police.
He was suspended from duty before resigning from the force earlier this month.
At Edinburgh Sheriff Court, McGinn pled guilty to supplying the drug, and to attempting to pervert the course of justice. Sentence was deferred.
Fiscal depute Neil Almond told the court that McGinn had been seconded to the Lothian and Borders drugs unit in September 2007.
He said that the force's professional standards unit was later given intelligence that McGinn was involved in the supply of controlled drugs, and was also using them himself.
A surveillance operation involving officers from Strathclyde Police was carried out.
On 4 October last year, McGinn was seen going into the Ship Inn pub in Mussleburgh, East Lothian, before leaving with a number of other men to go to a football match in the town.
When McGinn returned to the pub later that day, he was approached by two detectives as he sat in a car outside with another man.
The fiscal said: "As the accused was being handcuffed he said 'I'm a cop. I'm a cop. Lose it for me. Lose it for me please".
McGinn, who also managed Musselburgh Amateurs football club, was taken to Dalkeith Police Station where he was found to be in possession of two bags of cocaine and £198.46 in cash.
The bags of cocaine, weighing 3.34g and 984mg, were valued at £150.
A search of McGinn's former home in Prestonpans uncovered various items which were contaminated with the drug. The steering wheel, glove compartment and console of his car were also contaminated with cocaine.
The accused denied supplying drugs for money, saying he shared them with friends.
He also said he knew the people who supplied drugs, but would not name them "for friendship reasons".
McGinn, of Pathhead, Midlothian, told the officers he had bought the cocaine in the Ship Inn toilets for £300 in cash just 20 minutes before they found him in the car park.
He said he was using three and a half grammes a week and spending £520 a month on the drug.
Mr Almond said it was accepted that the supplying of the cocaine by McGinn was "at the lower end of the scale and there is no evidence he made financial gain".
McGinn had admitted accessing the Scottish Intelligence Database on "numerous occasions", but said it was "merely out of curiosity" and he denied he had ever passed on any information from it to anyone.
He resigned from the force earlier this month.
Sentence on McGinn, a first offender, was deferred until 23 October for reports. He was released on bail.
A spokesman for Lothian and Borders Police said had "failed to meet the standards" expected of one of its officers, and had "abused his position".
"When he was arrested in connection with this matter, he was immediately suspended and has subsequently resigned from the force," the spokesman added.