MEXICO CITY — President Andrés Manuel López Obrador has never been short of criticisms about his predecessor’s legacy. But he has reserved a special contempt for the sweeping overhaul that opened Mexico’s tightly held energy industry to the private sector.

He has called the changes a form of legalized “pillaging,” the product of corruption and a resounding failure. He has suggested that some foreign energy investors are “looting” the nation and that Mexican lawyers who work for them are guilty of treason.

He is now formalizing his most aggressive attack yet on the measures.

In the next few days, a bill that would strengthen the dominance of Mexico’s state-owned electricity company is expected to become law. The measure, which was recently approved by Mexico’s Congress with the forceful support of Mr. López Obrador, would also limit the participation of private investors in the energy sector. Both effects are central to his long-held aim of restoring energy self-sufficiency and safeguarding Mexican sovereignty.

Mexico’s dependence on foreign hydrocarbons was highlighted last month when a winter storm in Texas led to the interruption of natural gas deliveries from the United States, the source of most of the natural gas used in Mexico. Mr. López Obrador pointed to the ensuing blackouts as evidence of the need to lower dependence on foreign energy.

Yet the legislation, which was fast-tracked through Mexico’s Congress by Mr. López Obrador’s party, has faced almost universal criticism from opposition legislators, environmentalists, industry analysts, Mexican and international business groups and even Mexico’s antitrust watchdog.

Many critics see the bill as a political gambit to excite the president’s base ahead of midterm elections in June, through which Mr. López Obrador hopes to turn his party’s congressional majority into the supermajority needed to make changes to the Constitution.

Opponents of the legislation say that it would not only fail to resuscitate the energy sector or help achieve energy independence but that it would also violate Mexico’s international commitments to reducing carbon emissions, run afoul of trade agreements and further chill foreign investment in Mexico just as the nation is struggling to regain economic momentum amid the pandemic.

The legislation also threatens to throw another wrench into the relationship between the administrations of Mr. López Obrador and President Biden, which got off to a rocky start when the Mexican president became one of the last world leaders to congratulate Mr. Biden on his election victory.

“I think the impact of this reform is a major reversal,” said Lourdes Melgar, who was a top energy official in the administration of Mr. López Obrador’s predecessor, Enrique Peña Nieto. The Mexican president, she said, “has had a very nationalistic view of how to utilize resources.”

She added, “He wants to bring private producers to their knees, and we are seeing this in the most absurd ways.”

Jeremy M. Martin, vice president for energy and sustainability at the Institute of the Americas, a public policy think tank in San Diego, said the legislation probably resonates with Mr. López Obrador’s supporters, who have been made to feel that they finally have a president who is putting Mexican people first.

“It doesn’t make any economic sense, but it makes a great deal of sense to people who feel they’ve been screwed for years in Mexico,” he said. “It’s pure ideology, it’s political.”

The legislation would rewrite the rules governing the electricity sector. Among other changes, it would alter the so-called dispatch rules that govern the order in which plants feed their power into the nation’s grid, giving greater priority to plants run by the state electrical company, the Federal Electricity Commission.

The energy market liberalization approved in 2014 by the Mexican legislature prioritized low-cost power generation, which increasingly favored solar- and wind-generated power plants, inspiring a surge of private investment — from Mexico and abroad — in the renewables sector.

But the new legislation effectively restores preferences for state-run, fossil-fuel-driven plants that generate power at higher costs and produce greater carbon emissions.

Mr. López Obrador and his allies have argued that the bill seeks to correct a bias in the 2014 overhaul that, they say, gave unfair market advantages to private firms.

“We are leveling the floor, we are setting clear rules, we are prioritizing national security,” said Rocío Abreu Artiñano, a senator with the governing Morena party and president of the Mexican Senate’s energy commission.

The current scheme, she said, is “suffocating” the Federal Electricity Commission.

When more than 4.5 million homes and businesses in northern Mexico lost power last month after arctic weather froze cross-border pipelines and the governor of Texas issued an order to restrict natural gas exports, Mr. López Obrador said it was a lesson in the need for energy independence.

Gas-fired plants generate more than half of Mexico’s power; the vast majority of the natural gas is imported, with most of it coming from the United States, according to the Mexican government.

“We must always seek self-sufficiency, produce in Mexico what we consume: food, energy,” Mr. López Obrador said in mid-February as Mexico recovered from the blackouts.

But analysts and industry leaders say that the new legislation, despite Mr. López Obrador’s insistence that it will move Mexico toward greater energy independence, may actually make the nation more reliant on foreign sources of energy by increasing dependence on fossil fuels it needs to import.

Although household energy bills will probably remain insulated from price increases by government subsidies, industrial users could experience a rise in electricity costs that they would probably transfer to their customers, analysts said.

“This doesn’t have any economic logic,” said Víctor Ramírez Cabrera, spokesman for the Mexico, Climate and Energy Platform, a research group in Mexico City. He called the new model for power sourcing “absurd.”

Environmentalists and other critics have also savaged the legislation, saying it will reverse hard-fought gains in lowering carbon emissions and set Mexico on a course that runs counter to global efforts to address climate change, in violation of its international agreements and possibly its own laws.

Mr. López Obrador has said the government plans to upgrade its hydroelectric plants, which are given greater priority under the new energy sourcing scheme, to help meet its climate commitments. But critics of the legislation are deeply skeptical.

“There is no way to comply with the Paris Agreement under these conditions,” Mr. Ramírez said. “Just give it up for dead.”

Equally troubling, critics say, is the negative impact the legislation may have on foreign direct investment in Mexico. The law would essentially handicap many privately owned renewable-energy companies that have invested since the opening of the energy sector and cripple their chances of turning a profit.

“It’s going to hit them large and hard,” said Gonzalo Monroy, an energy consultant based in Mexico City.

Investors “came to invest in the country trusting in the rules, in the law,” said Xóchitl Gálvez Ruiz, a senator with the opposition National Action Party. “Overnight they are told, ‘You know what? I don’t like that, I’m going to change the rules.’”

Analysts and industry experts say litigation against the law is inevitable, including possible challenges on the grounds that it may contravene clauses in the United States-Mexico-Canada Agreement, which replaced the North American Free Trade Agreement.

The legislation is just the latest in what analysts say is a series of affronts to foreign investment by Mr. Lopez Obrador, including the cancellation of a $13 billion airport project in 2018 and the blocking of a partly built brewery in northern Mexico last year.

Following the Senate’s approval of the new law this past week, the peso dropped to a four-month low against the dollar. And a Reuters poll suggested that the currency could be in for an erratic few months in part owing to concerns over the energy overhaul.

“Investment levels are dropping, and nobody wants to invest here,” said Israel Tello, a legal analyst at Integralia, a Mexico City-based consultancy group. “Legal uncertainty is the most lethal weapon against investment.”