Jockey Nathan Evans took cocaine two days before a race meeting where he was caught with it in his system, a disciplinary panel heard.
The rider was tested ahead of the Goffs UK Premier Yearling Stakes at York on August 20, in which he finished eighth on sprinter Billian.
Seven days later, he learned his urine sample confirmed the presence of benzoylecgonine, a metabolite of the Class A drug.
The British Horseracing Authority suspended Evans and on September 22 he admitted what he had done in an interview.
On Friday he was handed a six-month ban.
Andy Howell, representing the BHA at the hearing, said the sportsman, who has held a licence since 2015, described how he ingested a “couple of keys of cocaine” while visiting friends in Newmarket.
“He says that if the York race was on the Thursday, then it was maybe the Tuesday that he took cocaine, so two days before racing,” Mr Howell said.
Evans, who listened to the enquiry via telephone, admitted a breach of the sport’s Rule (K)46.
His solicitor, Rory Mac Neice, said alcohol was the “trigger” for Evans taking cocaine for the first time.
He said he had previously been tested up to 25 times under the anti-doping rules and was addressing his issues with the help of Sporting Chance.
“This was an occasion when under the influence of alcohol he succumbed in circumstances where clearly he shouldn’t have done,” said Mr Mac Neice.
He added that his client was “deeply regretful” and he had spoken to his boss Mick Easterby about what happened.
Evans, who has ridden more than 150 winners in the past five years, is banned from the date of the positive test result.