But recently, executives at the last U.S. oil major in the country have debated whether it may be time to get out, according to people familiar with their deliberations.

For now, Chevron hopes to hang on and outlast President Nicolás Maduro, as it did with his late mentor Hugo Chávez and other rulers.

“We’re committed to our position in Venezuela,” Clay Neff, Chevron’s president of exploration and production in Africa and Latin America, said in an interview Thursday following initial online publication of this story.

Chevron’s dilemma is both moral and commercial. The California-based giant long enjoyed close relations with the socialist regime that controls the world’s largest oil reserves, and has earned big money in Venezuela—about $2.8 billion between 2004 and 2014, according to cash-flow estimates by analytics firmGlobalData .

The company is aware a pullout could trigger a collapse of the government’s finances, because a significant chunk of its scarce hard currency comes from joint operations with Chevron.

Chevron has had to put up with many provocations in Venezuela, including late payments, requests for employees to attend political rallies and bickering over loans Venezuela sought because it couldn’t afford oil-field maintenance. Chevron’s joint ventures with the state oil company are regularly subjected to what Venezuelan prosecutors have labeled corrupt overcharging by vendors. Graft and the risk it will worsen have weighed on executives as they consider Chevron’s position in the country.

It has become harder to stomach since the big money disappeared from the Venezuela operations, say people familiar with the company. Chevron operations in Venezuela lost money from 2015 to 2017, according to GlobalData, then eked out a modest profit this year thanks to higher oil prices. Oil fields are aging, and unless more reserves are opened up, Chevron’s work in Venezuela will run out of steam in less than five years, GlobalData estimates.

A turning point for foreign companies operating in Venezuela came in 2006, when Mr. Chávez began nationalizing oil fields managed by foreign operators and sharply raising taxes.

Rewritten contracts made Petroleos de Venezuela SA, known as PdVSA, the operator and majority owner of most projects. Chevron’s top U.S. competitors, Exxon Mobil Corp. and ConocoPhillips ,balked at the changes, left, and filed suit. Exxon has yet to recover the full value of the billions in equipment and other assets it left behind. ConocoPhillips recently reached a $2 billion settlement.

Some European oil companies, such as Total SA and Equinor AS A (then called Statoil), remained but reduced their holdings.

Chevron decided to stay, and—led by a charismatic Iranian-American executive named Ali Moshiri—formed an array of partnerships with PdVSA. Mr. Moshiri, who was head of Chevron’s business in Latin America and Africa, sometimes appeared in public with Mr. Chávez, who called him a “dear friend” on one occasion.

Joint ventures Mr. Moshiri pioneered became a model for foreign companies doing business in Venezuela. A venture called Petropiar between Chevron and PdVSA is one of four so-called upgrader ventures between the state oil company and foreign operators to blend Venezuela’s tar-like heavy crude with lighter oil or other substances and make it transportable.

Though Chevron’s bet paid off financially for years, an oil-price crash beginning in late 2014 triggered a vicious cycle in which government revenue fell and then oil production did, too, as the country placed priority on debt payments over the heavy reinvestment oil fields need to stay healthy.

Since the end of 2017, Venezuela has defaulted on more than $6 billion in debt payments, according to Fitch Ratings, while its crude-oil industry has been reduced close to ruins by neglect and the departure of experienced engineers.

Oil production has fallen to 1.2 million barrels a day from 3.2 million daily in 2006, according to the Organization of the Petroleum Exporting Countries. A country with vast reserves now produces roughly as much oil as the U.S. state of North Dakota. As output has declined, and thus revenue, the country’s economic crisis has worsened.

An investigation in the tiny European nation of Andorra has led to money-laundering charges against 28 people, including former Venezuelan deputy ministers, who allegedly took $2 billion through kickbacks-for-contracts schemes from 2007 through 2012.

Zair Mundaray, a former Venezuelan prosecutor now in exile, said his team uncovered an alleged scheme at the Petropiar joint venture in which PdVSA executives skipped formal contract bidding and handpicked the vendors of a wide range of supplies, from oil equipment to cafeteria coffee, at exorbitant prices. The profits were distributed among certain Petropiar managers, PdVSA higher-ups and the suppliers, the charging documents said.

Venezuelan charging documents and purchasing invoices reviewed by The Wall Street Journal allege that contractors pilfered more than $200 million in two years from the joint venture through markups such as $156,000 for printer/copiers and $9,000 for ink-jet cartridges.

Among the accused was Manuel Sosa, a former soap-opera actor who once dated a daughter of Mr. Chávez, whose company supplied the costly printer/copiers. Mr. Sosa pleaded guilty in December and was sentenced to four years’ house arrest in return for his cooperation. He couldn’t be reached for comment.

“Where were the checks? Where was the accounting?” asked Mr. Mundaray. “There’s absolutely no way that [Chevron] did not know what was happening.” He said he has given the evidence he collected to the U.S. Justice Department, which declined to comment.

Pedro Burelli, a former PdVSA board member and a Maduro critic, said Chevron “turned a blind eye to what was going on.”

“When you’ve agreed to work with a majority partner that is derelict, you’re just setting yourself up for a huge risk. You get deeper and deeper, when you should be hitting the red button, to get yourself out,” said Mr. Burelli.

Chevron said it complies with all applicable laws wherever it operates and expects its partners to do so as well. It said it doesn’t control the procurement process in the joint venture, in which Chevron has a 30% nonoperating stake. In oil and gas joint ventures, the operator typically has primary authority over costs, though minority partners are generally consulted and sign off on certain expenses. Chevron said nothing in documents it was shown suggested any wrongdoing by the U.S. company.

Oversight of the investigation changed hands just as it was picking up steam. Mr. Mundaray and his team left Venezuela in August 2017 after their boss, former Attorney General Luisa Ortega, criticized Mr. Maduro for alleged human-rights abuses. The president called the prosecutors traitors.

A new attorney general, Tarek William Saab, provided a list of people accused that lacked some names on Mr. Mundaray’s list.

One missing name was that of former Petropiar chief Francisco Velasquez, who the former prosecutors said splurged on a pink Ferrari and a villa at the exclusive Casa de Campo resort in the Dominican Republic while the oil project suffered backlogs and delays. He couldn’t be reached for comment. Mr. Saab didn’t respond to comment requests.

In April, two Chevron employees working at the Petropiar joint venture were jailed by Venezuelan military intelligence when they refused to sign a contract for oil-processing equipment priced at what they considered well above market value. The employees were released after six weeks of tense negotiations, but not before a thinly veiled threat from Chevron: free them or we will leave, people familiar with the confrontation say.

Chevron confirmed two employees were arrested in April and released in June but said, “We have no further information to share on this matter.”

A dwindling number of foreign companies are still doing business with the Maduro administration, which is facing threats of tougher sanctions by Washington. The U.S. has sanctioned dozens of Venezuelans, including Mr. Maduro, for allegations varying from corruption to human-rights abuses to drug trafficking. The sanctions bar American citizens and companies from doing business with them.

Mr. Maduro has said he wants foreign oil partners to use a cryptocurrency called the petro his government designed to evade U.S. sanctions on Venezuelan debt. The U.S. in March barred Americans from using the petro.

By staying in Venezuela, Chevron risks exposing itself to legal penalties under U.S. anti-corruption laws, some analysts say. Chevron said it “abides by a strict code of business ethics under which the company complies with all applicable international, U.S. and Venezuelan laws.”

Its managers’ meetings with government and PdVSA officials “comply with all applicable laws and regulations, including the U.S. sanctions directed towards Venezuela,” Chevron said.

About 700,000 daily barrels of the country’s oil production comes from joint ventures between PdVSA and foreign companies, consultants say. That includes about 200,000 to 250,000 barrels a day from Chevron ventures.

Joint-venture output has generated far more cash for the government in recent years than oil pumped by PdVSA alone, because the state company’s production has gone to repay debts to allies such as China and Russia or to be processed into gasoline the government provides almost free. That means a Chevron withdrawal would take a big bite out of government’s revenue.

Another foreign company, Royal Dutch Shell PLC, is weighing an exit from most of its remaining operations in Venezuela through a sale of its stake in a joint venture, according to people familiar with its plans. A spokeswoman for Shell said such a deal wouldn’t amount to a total exit, as the company is working to develop Venezuelan gas assets offshore that would supply nearby Trinidad and Tobago.

Some analysts believe other Western companies operating in Venezuela, such as France’s Total or Norway’s Equinor, might feel pressure to follow a departure or partial exit by either Shell or Chevron. At the same time, according to GlobalData, those that stay might be able to gain access to new fields or renegotiate contracts for better terms. Chinese or Russian companies such as PAO Rosneftcould be beneficiaries of any such departures in the long run, analysts say.

Total, Equinor and Rosneft officials either declined to comment or didn’t respond to questions.

Signs of a troubled relationship between Chevron and the Venezuelan government emerged a year ago when Mr. Moshiri’s successor as head of Chevron’s Latin American and African operations, Mr. Neff, sat down for a meeting with Mr. Maduro and other Venezuelan officials.

Venezuelan officials snapped a photo without Chevron’s consent and publicized it. At Chevron headquarters in San Ramon, Calif., concerns grew that the company was being duped into making an appearance in Venezuelan propaganda, people familiar with the matter said.

While such photo ops had occurred before, the country’s worsening economic collapse, plus U.S. sanctions, are making them harder to tolerate, the people said. Chevron declined to discuss the Caracas meeting.

The company’s closeness with the government is generating rancor among PdVSA’s workers, who have been quitting in droves amid hyperinflation that has pummeled their salaries to the equivalent of less than $10 a month.

Jose Bodas, a union leader in eastern Venezuela where Petropiar is located, said photos of sports cars and European vacations posted on social media by managers angers workers who sometimes lack boots and hardhats.

“I’m not opposed to people having Ferraris and mansions, but this is all corruption,” Mr. Bodas said. “I don’t mind saying it—if you’re a multinational working with this government, you’re an accomplice to what’s going on.”