Chevron Corp posted a better-than-expected 24 percent rise in quarterly earnings on Friday on higher profits from its refineries and a gain from the sale of its stake in power company Dynegy Inc.

Net income in the second quarter increased to $5.38 billion, or $2.52 a share, from $4.35 billion, or $1.97 a share, last year.

Excluding the $680 million gain on sale of Dynegy stock and a $160 million loss on debt redemption, the company would have posted earnings of about $2.37 a share. On that basis, the average forecast of Wall Street analysts was $2.30 a share, according to Reuters Estimates.

Total revenue in the quarter rose to $56.09 billion from $53.54 billion last year.

Earnings at Chevron's exploration and production unit rose to $3.64 billion from $3.27 billion last year, when the company recorded about $300 million in charges from hurricane damages in the Gulf of Mexico.

Production in the quarter dropped about 1 percent to 2.63 million barrels of oil equivalent per day due to changes in ownership at the company's operations in Venezuela and lower U.S. production.

Income from the company's downstream segment -- which includes its refining, marketing and transportation businesses -- rose 30 percent to $1.3 billion.

The second-quarter was a mixed bag for integrated oil companies -- many saw better-than-expected profits on the back of strong refining margins, while others had results dip as those profits from gasoline production were offset by lower output and commodity prices.

Chevron's shares rose 0.5 percent to $87.88 in early trading on the New York Stock Exchange on Friday.

Through Thursday's close, Chevron's shares are up about 19 percent this year, outperforming the Chicago Board Options Exchange's oil index, which rose over 17 percent in the same period.

(Reporting by Michael Erman)