Weaker global oil prices have weighed on earnings across the sector and Exxon also felt the sting of decade-low U.S. natural gas prices, especially in the United States where it is the largest producer of the fuel.

The company, which has pledged to spend a record $37 billion this year as it brings new projects on line in countries including Canada, Papua New Guinea and the Gulf of Mexico said oil and gas output fell 5.6 percent to 4.15 million barrels oil equivalent per day during the quarter.

"I think the big issue for the oil majors is they need high oil prices for all these exploration costs to pay off," said Michael Yoshikami, CEO of investment advisor Destination Wealth Management. "At $100 to $110 (per barrel), I think they are fine."

Exxon is hoping those new projects will boost its long-term oil and gas output, since Wall Street has long pointed to weak growth as a problem for the oil majors.

Analysts honed in on those figures again, but saw other issues as well.

"Production was a little light," Pavel Molchanov, analyst at Raymond James, said. "The real swing versus our estimates was chemicals."

Chemical demand in Europe was weak and commodity margins were pinched in Europe and Asia, David Rosenthal, an investor relations executive with Exxon, told investors on a conference call.

The Irving, Texas, company reported a second-quarter profit of $15.9 billion, or $3.41 per share, up from $10.68 billion, or $2.18 per share, a year earlier.

Profit was boosted by a $7.5 billion gain related to the sale of a stake in its Japanese refining and chemicals business, and tax items.

Excluding those one-time gains, Exxon earned $8.4 billion, or $1.80 per share. On that basis, analysts' average forecast was $1.95, according to Thomson Reuters I/B/E/S.

Excluding one-time items, earnings from the company's chemical operations totaled $820 million, nearly 33 percent below Raymond James' estimate for the unit, Molchanov said.

Analysts at Barclays had looked for Exxon to report chemical earnings of $859 million.

Weakness in the chemicals market was also evident in the earnings of Dow Chemical Co, which reported a 34 percent drop in quarterly profit, missing Wall Street forecasts.

Earlier on Thursday, Royal Dutch Shell posted lower-than-expected quarterly earnings of $5.7 billion, hurt by maintenance costs and shutdowns in the U.S. Gulf, where the company has some of its most profitable production, and in Australian Liquefied Natural Gas.

Exxon's earnings from U.S. oil and gas production tumbled by more than half in the second quarter to $678 million, largely due to the steep decline in prices of natural gas.

The company is the nation's largest producer of natural gas, but Chief Executive Officer Rex Tillerson warned last month that prices were too low to allow the industry to cover the cost of finding and producing new supply.

"We are all losing our shirts today," Tillerson said at the time.

Exxon shares rose 0.8 percent to $85.94 in midday trading on the New York Stock Exchange, helped by a rebound in oil futures prices.

(Reporting By Anna Driver in Houston and Matt Daily in New York; editing by John Wallace and Marguerita Choy)

By Anna Driver and Matt Daily