Exxon Mobil said on Sunday that it had agreed to sell its Japanese subsidiary to TonenGeneral Sekiyu, a major refinery operator in Japan, for about $3.9 billion, as part of a revamping of the oil giant’s operations in that country.

Under the terms of the deal, Exxon will sell a 99 percent stake in the subsidiary, ExxonMobil Yugen Kaisha, to TonenGeneral. Exxon will in turn shed most of its controlling stake in TonenGeneral, keeping a 22 percent interest in the Japanese refiner.

The deal represents the latest move by Exxon and other major oil companies to shift their focus from refining operations to higher-margin businesses like exploration and development of new sources of oil and natural gas.

There is surplus refinery capacity in many parts of the world in large part because of the economic downturn, which has sliced into demand for gasoline and other petroleum products.

Meanwhile, high oil prices and relatively low gasoline prices have squeezed refinery profits. Royal Dutch Shell and BP are selling refineries in Western Europe and the United States. Several refiners have closed a handful of refineries on the East Coast in recent years, and a few are up for sale. ConocoPhillips plans to separate its refinery operations from oil and gas exploration and production.

TonenGeneral will also streamline its operations in light of what it says is declining demand for oil in Japan, which has put pressure on the company’s profit margins.

“The company will be able to more effectively execute locally driven investments and other business decisions that will help the company adapt to the challenging operating environment,” TonenGeneral said in a statement.

TonenGeneral will continue to have exclusive use of Exxon brands like Esso, Mobil and General in Japan. Exxon will also provide technology and supply services to TonenGeneral.

The Japanese refiner plans to finance the transaction with some of its 100 billion yen ($1.3 billion) in cash on hand and with bank debt. The deal is expected to close by June 1.

TonenGeneral was advised by Nomura Securities and the law firm Nishimura & Asahi.