Two pipeline companies agreed on Tuesday to merge in a deal that could create the largest energy-infrastructure company in North America.

The companies, Enbridge and Spectra Energy, signed a stock-for-stock deal, where Enbridge shareholders will own about 57 percent of the combined company and Spectra’s will own 43 percent, according to a statement released by the companies on Tuesday.

Spectra shareholders will get 0.984 shares of the combined company for each share they own, valued at about $40.33 a share, based on share prices on Sept. 2. The transaction values Spectra’s common stock at about $28 billion.

Pipeline companies help transport oil, natural gas and other liquids across the country. Pipeline companies had traditionally been seen as an energy investment relatively immune from the price swings of the commodities they carry because they lock in long-term contracts. But after a plummet in energy prices last year, investors became skittish about pipelines as well because many of their customers were on the brink of bankruptcy.