What happened

Shares of Magellan Midstream Partners (MMP) shot up this week, trading 13% higher as of noon Friday, according to data provided by S&P Global Market Intelligence.

Ironically, several analysts downgraded the midstream energy stock over the past few days, but investors had a valid reason to rejoice.

So what

Earlier in May, Magellan Midstream reported solid 18% year-over-year growth in its distributable cash flow (DCF) and a whopping 65% growth in net income for the first quarter. A strong first quarter even encouraged management to raise its DCF outlook for 2023. Until then, no one had an inkling about what was to come up after 10 days.

On May 14, Magellan announced that it was selling itself to Oneok (OKE -1.02%) in a cash-and-stock deal valued at nearly $18.8 billion, including assumed debt. Magellan's shareholders will receive $25 in cash and 0.6670 shares of Oneok for every Magellan stock they own. That effectively valued the deal price to be $67.5 per share for Magellan, representing a 22% premium from the stock's closing price on its prior trading day.

Not surprisingly, Magellan's shares, which closed at $55.41 apiece on May 12, jumped by double-digit percentages after the deal was announced. Oneok stock, on the other hand, slumped as investors tried to analyze whether the company's move to pay such a high premium and pivot toward the volatile crude oil side of the industry could prove costly in the long run.

Now what

Magellan's stock was downgraded by analysts from Citi, RBC Capital, and Truist this week, but it was mostly a reaction to the stock price's run-up close to the deal value. Analysts at Truist, for example, cut the stock's price target to $66 per share from $71 a share.

With Magellan stock inching close to the deal price, some investors may already want to cash out. That may not be required yet, as staying invested in Oneok after the deal -- which is expected to close in the third quarter -- could be a prudent move. That's because the acquisition will create one of the world's largest energy infrastructure companies in the U.S. Also, while Magellan was focused on crude oil, Oneok is a natural-gas play, and the diversification could prove beneficial to Magellan investors in the long run.

The two companies also expect the deal to be accretive to earnings per share from 2024 and boost free cash flow (FCF) per share by more than 20% on average from 2024 through 2027. Since dividends depend directly on a company's FCF, that also means Magellan shareholders who have enjoyed big dividends from the master limited partnership so far needn't worry. Oneok already has a solid dividend profile, having grown its dividend payout by a compound annual rate of 12% since 2000 and sporting a 6.5% yield.