Marathon Petroleum Corp. said on May 8 it would merge its midstream units in a $9 billion deal, and posted a surprise first-quarter loss due to higher prices of Canadian crude.

The refiner said in October it planned to assess options for the two master limited partnerships, MPLX and Andeavor Logistics LP, which transport, store and market its products through pipelines, terminals and trucking operations.

Under the terms of the agreement, Andeavor shareholders will receive 1.135 common units of MPLX for each common unit held and Marathon will receive 1.0328 MPLX common units for each ANDX common unit held.

The deal has an enterprise value of $14 billion and will close in the second half of the year.

Marathon has been strengthening its midstream operations and retail unit, which includes Speedway gas stations and convenience stores and Andeavor's retail and direct dealer business, to diversify its revenue streams beyond refining.

Findlay, Ohio-based Marathon also reported a first-quarter loss, compared with a year-ago profit, as its refining segment posted a bigger loss due to narrower crude discounts.

Net loss attributable to Marathon was $7 million, or 1 cent per share, in the three months ended March 31, compared with a profit of $37 million, or 8 cents per share, a year earlier.

Excluding items, the company reported a loss of 9 cents per share, while analysts had expected a profit of 5 cents, according to IBES data from Refinitiv.

Total revenue rose nearly 51 percent to $28.62 billion.

The company said it had decided not to pursue the Garyville Coker 3 project, which aimed to increase coking capacity at its Garyville refinery by 50 percent.

Marathon's shares were down nearly 2% at $58.32 in premarket trade.