Soldiers who bought more than 100 prescription pills, got high and attacked a table with a machete have been discharged.

The four New Zealand soldiers stocked up on pills from a pharmacy in Suva, Fiji — where they were helping clean up after Cyclone Winston in 2016 — before smuggling them on board HMNZS Canterbury.

Their commanding officer uncovered the drug-taking when a soldier smashed a table with a machete and another was seen "flipping out", NZ Herald reported.

The pills included Valium, tramadol and Viagra, the site said, and were stashed in cyclone-damaged property as well as in a light fitting.

A pair of the men hid pills in a leather bible cover they hid inside a ruined house.

Commander Simon Rooke said of his encounter with one of the men: "I have spent 25 years watching and talking to sailors in various situations and consider I'm pretty good at smelling a lie, and he stunk of it."