Ecolab Inc. has agreed to spin off one of its energy businesses and simultaneously merge it with a Texas company to create a company with $3.5 billion in sales.

The deal announced Thursday would combine Ecolab’s $2.4 billion “upstream” energy business — which supplies chemicals and services to companies drilling for oil and will be renamed ChampionX — with Texas-based Apergy Corp. in a complex, tax-free deal. The combined company would have about $615 million in pretax profits, Ecolab said.

Ecolab’s stock rose 3% Thursday to close at $191.78 per share.

St. Paul-based Ecolab had said earlier this year that it wanted to find a way to spin off its upstream business in 2020. The merger deal builds upon the prior plan.

“This transaction is a terrific development,” said Ecolab CEO Douglas Baker in a statement.

Ecolab is keeping its “downstream” energy business, which serves refineries and petrochemical plants.

Officials said the upstream deal will create an entity with a strong balance sheet and cash flow and a larger geographic footprint than previously available. The combined entity will have 8,000 employees, including about 5,000 who will transfer over from Ecolab.

The merger is expected to produce “significant synergies” with savings of about $75 million a year and “drive even more attractive shareholder value for Ecolab shareholders than our original spin plan,” Baker said. “We expect this to be a smooth transition for the business.”

Under the agreement, Apergy shareholders will own 38% of the combined company; Ecolab shareholders will own 62%. The deal has a “combined enterprise value” of $7.4 billion, with $3.9 billion worth of stock for Ecolab shareholders and a cash payment of about $492 million to Ecolab.

Deric Bryant, Ecolab’s current president of the Upstream Energy business, will move to the new entity, which he will help run.

“Together our two businesses will offer a compelling value proposition to our production-focused customer base,” Bryant said.

Apergy CEO Sivasankaran Somasundaram said the deal will accelerate Apergy’s strategic goals of broadening both the company’s product offerings and its geographic footprint.