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, an Associated Press investigation finds the military made a profit from controlling much of the food distribution. 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."

In this Nov. 14, 2016 photo, a truck driver rests on his hammock under his truck as he waits to enter the port in Puerto Cabello, Venezuela. Ariana Cubillos / AP

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, the AP found. And from generals to foot soldiers, the military is at the heart of the graft, according to documents and interviews with more than 60 officials, business owners and workers, including five former generals.

RELATED: Venezuela: Pirates Terrorizing Fishermen as Industry Crumbles

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

The U.S. government has taken notice. Prosecutors have opened investigations against senior Venezuelan officials, including members of the military, for laundering riches from food contracts through the U.S. financial system, according to four people with direct knowledge of the probes. No charges have been brought.

In this Nov. 18, 2016 photo, people wait outside a supermarket to buy government subsided food in Caracas, Venezuela. Ariana Cubillos / AP

"Lately, food is a better business than drugs," said retired Gen. 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 nationalized 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 the country needed.

RELATED: 'We're Hungry': Thousands Protest in Venezuela's 'Toma de Caracas'

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

In this Nov. 1, 2016 photo, a man cooks chicken skin he found at the dump in Puerto Cabello, Venezuela, the port city where the majority of Venezuela's imported food arrives. Ariana Cubillos / AP

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."

One South American businessman said he paid millions in kickbacks to Venezuelan officials as the hunger crisis worsened, including $8 million to people who work for the current food minister, Gen. Rodolfo Marco Torres. The businessman insisted on speaking anonymously because he did not want to acknowledge participating in corruption.

Last July, he struggled to get Marco Torres's attention as a ship full of yellow corn waited to dock.

"This boat has been waiting for 20 days," he wrote in text messages seen by AP.

"What's the problem?" responded Marco Torres.

In this Nov. 1, 2016 photo, a man carries bags of recyclable material he collected at the dump in Puerto Cabello, Venezuela. Ariana Cubillos / AP

Although money was not mentioned, the businessman understood that he needed to give more in kickbacks. In the end, he told the general, the boat had to pull out because costs caused by the delay were mounting.

Bank documents from the businessman's country show that he was a big supplier, receiving at least $131 million in contracts from Venezuelan food ministers between 2012 and 2015. He explained that vendors like him can afford to pay off military officials because they build huge profit margins into what they bill the state.

For example, his $52 million contract for the yellow corn was drawn up to be charged at more than double the market rate at the time, suggesting a potential overpayment of more than $20 million for that deal alone.

RELATED: Some Poor Venezuelan Parents Give Away Children Amid Deep Crisis

The Food Ministry's annual report shows significant overpayments across the board, compared to market prices. And the prices the government pays for imported foods have been increasing in recent years, while global food prices remain stable.

In this Nov. 14, 2016 photo, young men climb into an empty food truck, in search of leftover grain, as the vehicle comes to a slow stop outside the port in Puerto Cabello, Venezuela. Ariana Cubillos / AP

This spring, the opposition-controlled congress voted to censure Marco Torres for graft. Maduro vetoed it as an attempt to hurt the Food Ministry, and Marco Torres stayed on as minister.

Internal budgets from the ministry obtained by AP show the overpayment continues. For example, the government budgeted for $118 million of yellow corn in July at $357 a ton, which would amount to an overpayment of more than $50 million relative to prices that month.

"What's amazing about this is it's like a clean form of corruption," said Carabobo state lawmaker 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."

Marco Torres did not respond to several requests for comment by phone, email and hand-delivered letter. In the past, he has said that he will not be trapped in fights with a bourgeoisie opposition.

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 Gen. 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."

However, it also opened the door to widespread graft and further squeezed the food supply. In large part due to concerns of corruption following the government's takeover of the food industry, the three largest global food traders — U.S.-based Archer Daniels Midland Co., Bunge Ltd. and Cargill — have stopped selling to the Venezuelan government.

One major scam involves the strict currency controls that have been a hallmark of the administration. The government gives out a limited amount of coveted U.S. currency at a rate of 10 bolivars to the dollar. Almost everyone else has to buy dollars on the ever more expensive black market, currently at 3,000 bolivars to the dollar.

The holders of licenses to import food are among the select few who get to buy dollars at the vastly cheaper rate. Alcala, the retired general, said some officials distribute these much-desired licenses to friends. The friends then use only a fraction of the dollars to import food, and share the rest with the officials.

"We call it 'scraping the pot,' and it's the biggest scam going in Venezuela," Alcala said.

Follow NBC Latino on Facebook, Twitter and Instagram.