A cannabis user caught trying to move six kilos of the drug from Tadcaster to Manchester has avoided a return to jail.

Michael Martin, 23, was one of three balaclava-clad men who "liberated" some of the drug from a £500,000 Tadcaster cannabis factory that didn't belong to them, Nick Adlington, prosecuting, told York Crown Court.

But North Yorkshire Police were already planning to close down the factory and arrested him in the town. They also confiscated the raiders' 5.87kg haul of cannabis which was worth between £41,275 and £57,785 in street deals.

Martin, of Clifton, Swinton, near Manchester, pleaded guilty to possessing cannabis with intent to supply it to others on the basis that he was only the driver for the raiders and had nothing to do with setting up or running the cannabis factory.

Mr Adlington said the cannabis farm in Grange Lane, Tadcaster, had 1,200 plants, some of which had been harvested, and was capable of producing cannabis worth up to £500,000.

Martin's barrister Sara Haque said he hoped to start a new job working as a delivery driver for a firm near his home.

Recorder Tahir Khan QC said because Martin had spent the equivalent of a six-month sentence on remand, he could pass a non-custodial sentence. He ordered Martin to do nine months' supervision and 80 hours' unpaid work.

Mr Adlington said police were planning to raid the cannabis factory on February 2, 2013, and already had a warrant, but on January 31 at 8.25pm, a member of the public warned them of three men in balaclavas with two vans in the area. In the police chase that followed, all three escaped on foot leaving the "liberated" cannabis behind, but officers stopped Martin's girlfriend in Kirkgate, Tadcaster, nearly two hours later who had just arrived in a taxi from Manchester.

She claimed she had come to collect her boyfriend whose car had broken down, but when Martin appeared, police arrested both of them.

By then, police had brought their raid on the cannabis factory forward, searched it and arrested two Vietnamese men in its garden.

Miss Haque said Martin was reducing his cannabis habit and sorting his life out.

Two other Mancunians were acquitted by a York jury last month of being the other two men in balaclavas.