Warren Buffett has famously said that one of the best ways to make money in investing is to "be greedy when others are fearful." Well, with inflation fears spiking in recent weeks, and sending stocks tumbling, oil refiner Phillips 66 (PSX -2.51%) decided to take Buffett's advice to heart and buy back a big chunk of its own stock. The seller was none other than Buffett's Berkshire Hathaway (BRK.A 0.64%) (BRK.B 0.54%).

Details on the deal

Phillips 66 announced this week that it had agreed to repurchase 35 million of its shares from a subsidiary of Berkshire Hathaway for $93.73 apiece, or about $3.3 billion. That repurchase price is significantly less than the shares fetched not that long ago, with the stock closing at more than $106 per share in late January. That's a double-digit discount to that recent high.

Double exposure of a handshake between two men, with a refinery at nighttime in the background.

Image source: Getty Images.

However, it wasn't the stock's recent slump that led Buffett to sell. Instead, according to the billionaire investor, "This transaction was solely motivated by our desire to eliminate the regulatory requirements that come with ownership levels above 10%. We remain one of Phillips 66's largest shareholders and plan to continue to hold the stock for the long term."

After closing this sale, Berkshire Hathaway will hold 45.7 million shares of Phillips 66, or about 9.8% of the total shares outstanding. That's down from a more than 16% stake in the company before this week's sale.

While Buffett did miss selling at the most recent top, Berkshire has done exceptionally well with its investment in Phillips 66. In 2016, the company held 55.4 million shares of the oil refiner that it bought for an average purchase price of $78.67 apiece, including buying 18 million shares that year for $77.23 per share. At that purchase price, Buffett would have booked a nearly 20% gain on this sale.

A storage tank with the sun rising in the background.

Image source: Getty Images.

Holding the rest for the long term

While Buffett is trimming his position in Phillips 66, he is still the company's largest shareholder, and it will remain a top 10 holding for Berkshire. That's because he still believes "Phillips 66 is a great company with a diversified downstream portfolio and a strong management team." Fueling Buffett's continued belief in Phillips 66 was its strong performance in 2017 as well as what lies ahead.

While last year was another tough one for the energy sector, Phillips 66 generated $3.6 billion in cash flow, up from $3 billion in 2016. The company returned $3 billion of that cash to investors via share buybacks and dividends, including raising its payout 11%. Meanwhile, it made excellent progress completing its growth projects, including starting up the Bakken Pipeline, adding more storage capacity at its Beaumont Terminal, and finishing up a $6 billion chemicals expansion along the Gulf Coast with joint venture partner Chevron (NYSE: CVX). These projects position Phillips 66 to generate even more cash flow this year, which is why the company authorized an additional $3 billion share repurchase program last October.

Even with all that progress, Phillips 66 still has plenty of growth left in the tank since it's kept working on expansion projects that will drive cash flow higher in the coming years. For example, in December the company announced it was partnering with Canadian pipeline giant Enbridge (NYSE: ENB) on the Gray Oak Pipeline, which would transport oil from the fast-growing Permian Basin to markets along the Gulf Coast, including refineries operated by Phillips 66.

In the meantime, the company's two master limited partnerships, Phillips 66 Partners (PSXP) and DCP Midstream (DCP) (which it co-owns with Enbridge), pressed forward with several new projects. Phillips 66 Partners plans to build a new unit at Phillips 66's Lake Charles Refinery that will help it boost production of higher octane gasoline. In addition, both Phillips 66 Partners and DCP Midstream are working to expand their Sand Hills NGL pipeline. Finally, DCP Midstream recently signed on as a partner in a major natural gas pipeline project in the Permian Basin. Cash from these expansions will eventually flow up to Phillips 66 as they come on line in the coming years.

Know when to hold 'em

While Buffett chose to part with a portion of his stake in Phillips 66, it's not because he no longer believes in the company but because the position had grown too large. That's why investors shouldn't sell just because he is, but instead consider holding for the reasons he's holding, which is the belief that over the long term, Phillips 66 will continue to create value for shareholders.