When hunger drew tens of thousands of Venezuelans to the streets in protest last summer, President Nicolas Maduro turned to the military to manage the country's diminished food supply, putting generals in charge of everything from butter to rice.

But, instead of fighting hunger, the military is making money from it, an Associated Press investigation shows. That's what grocer Jose Campos found when he ran out of pantry staples this year. In the middle of the night, he would travel to an illegal market run by the military to buy pallets of corn flour - at 100 times the government-set price.

"The military would be watching over whole bags of money," Campos said. "They always had what I needed."

With much of the country on the verge of starvation and billions of dollars at stake, food trafficking has become one of the biggest businesses in Venezuela. And from generals to foot soldiers, the military is at the heart of the corruption, according to documents and interviews with more than 60 officials, business owners and workers, including five former generals.

As a result, food is not reaching those who most need it.

"Lately, food is a better business than drugs," said retired General Cliver Alcala, who helped oversee Venezuela's border security. "The military is in charge of food management now, and they're not going to just take that on without getting their cut."

After opposition attempts to overthrow him, the late president, Hugo Chavez, began handing the military control over the food industry, creating a Food Ministry in 2004. His socialist-run government nationalised farms and food processing plants, then neglected them, and domestic production dried up.

Oil-exporting Venezuela became dependent on food imports, but when the price of oil collapsed in 2014, the government no longer could afford all that the country needed.

Food rationing grew so severe that Venezuelans spent all day waiting in lines. Paediatric wards filled up with underweight children, and formerly middle-class adults began picking through rubbish bins for scraps. When people responded with violent street protests, Maduro handed the generals control over the rest of food distribution, as well as the country's ports.

The government now imports nearly all of Venezuela's food, according to Werner Gutierrez, the former dean of the agronomy school at the University of Zulia, and corruption is rampant, jacking up prices and leading to shortages.

"If Venezuela paid market prices, we'd be able to double our imports and easily satisfy the country's food needs," Gutierrez said. "Instead, people are starving."

READ MORE: Cash chaos in Venezuela after banknote withdrawn

The Food Ministry's annual report shows significant overpayments across the board, compared to market prices.

"What's amazing about this is, it's like a clean form of corruption," said Carabobo state legislator Neidy Rosal, who has denounced food-related government theft worth hundreds of millions of dollars. "It's like drug trafficking you can carry out in broad daylight."

By putting the military in charge of food, Maduro is trying to prevent soldiers from going hungry and being tempted to participate in an uprising against an increasingly unpopular government, said retired General Antonio Rivero. Venezuela's military has a long history of coups against governments and Maduro has arrested several officials for allegedly conspiring against him from within.

"They gave absolute control to the military," Rivero said from exile in Miami. "That drained the feeling of rebellion from the armed forces, and allowed them to feed their families."

The Defence Ministry and presidential press office refused to answer repeated calls, emails, and hand-delivered letters requesting comment. In the past, officials have accused the opposition of exaggerating the problem of corruption for political gain. They have said the military's hierarchical structure makes it ideally suited to combat the real culprits: right-wing businessmen trying to bring down the economy.

And yet the corruption persists, from the port to the markets, according to dozens of people working in Puerto Cabello, the town that handles the majority of Venezuela's food imports.

Bribes are also required for any missing paperwork and can exceed $10,000 for a single shipping container, customs worker Aldemar Diaz said.

"Sometimes, you actually want to do it legally, but the officials will say, 'don't bother'," he said.

Luis Pena, operations director at the Caracas-based import business Premier Foods, said he pays off a long roster of military officials for each shipment of food he brings in from small-scale companies in the US.

"You have to pay for them to even look at your cargo now," he said. "It's an unbroken chain of bribery from when your ship comes in until the food is driven out in trucks."

READ MORE: Venezuela - Patients dying as crisis hits hospitals

Lieutenant Miletsy Rodriguez, who is in charge of a group of national guardsmen running security at the port, said people are just looking to scapegoat the military. If her unit wasn't around, looting would be even more widespread, she said.

"The majority of us are doing our best. And, sooner or later, we'll catch people who are not doing the job right," she said.

In Puerto Cabello, hungry residents said it feels like corrupt soldiers are taking food off their children's plates.

Pedro Contreras, 74, watched more than 100 trucks carrying corn rattle onto the highway and walked stiffly into traffic to sweep up the kernels that had sifted out. He planned to pound them into corn flour that night to feed his family.

"The military is getting fat while my grandchildren get skinny," he said. "All of Venezuela's food comes through here, but so little of it goes to us."