Authorities in Texas said bananas donated to a prison in the state turned out to have nearly $18m worth of cocaine hidden inside their boxes.

The Texas department of criminal justice (DCJ) outlined the find in a surprisingly jaunty Facebook post which began: “Sometimes, life gives you lemons. Sometimes, it gives you bananas. And sometimes, it gives you something you’d never expect!”

The two pallets of bananas were donated because they were already ripe, the DCJ said, and arrived on Friday from Ports of America in Freeport.

“One of the boxes felt different than the others,” the DCJ said. “[Officials] snipped the straps, pulled free the box, and opened it up.

“Inside, under a bundle of bananas … another bundle! Inside that? What appeared to be a white powdery substance. They immediately notified port authorities and awaited their instruction.”

The pallets turned out to contain “quite the cache”, the DCJ said: 540 packages of cocaine in 45 boxes of bananas, “with an estimated street value of $17,820,000” .

The DCJ said federal officials and US Customs and Border Protection were investigating.

“What a find by the boys in grey!” it said.