By Anna Hirtenstein and David Benoit

The Dow Jones Industrial Average rose Tuesday, boosted by better-than-expected earnings from some of the biggest U.S. companies and a fiscal stimulus package from the European Union.

The Dow industrials gained 313 points, or 1.2%, while the S&P 500 rose 0.5%.

Rising shares of Coca-Cola and IBM helped power the gains, after both companies managed to perform better than analysts' dour expectations.

Shares of Coca-Cola rose 2.4% after the company said revenue fell 28% as lockdowns to stop the spread of the coronavirus sunk sales of its beverages at restaurants, movie theatres and stadiums. But the company also said the worst was behind it and July was shaping up better.

IBM also managed a better-than-expected second-quarter profit, as sales fell just 5.4% and it got a big boost from cloud-computing revenue, up 30%. The tech company rose 0.6%, even as other tech giants pared recent gains. The Nasdaq Composite slipped 0.5%, a day after a closing at a fresh record.

Earnings are still expected to fall roughly 44% compared to a year ago for S&P 500 companies, according to analysts polled by FactSet. A wave of expected reports throughout the week, including big names like Amazon.com, Microsoft, and American Express, will shed further light on the economic views of business leaders.

Also powering stocks and other global assets higher was a historic pact reached overnight in the European Union to ease the economic blight of the coronavirus. The bloc agreed on terms terms for a EUR1.8 trillion ($2.06 trillion) spending plan. The package will center around the bloc's first-ever issuance of common bonds, and could help deepen the bloc's economic integration. The pan-continental Stoxx Europe 600 rose 0.4%, paring earlier gains.

"Having an agreement on fiscal coordination in a time of crisis ... probably gives Europe a level of stability it has lacked," said David Kelly, the chief global strategist at JPMorgan Asset Management. "That really is a big deal."

The pact helped boost global energy prices. A rally carried Brent crude up 2.2%, pushing it above $42 a barrel for the first time since early March when prices plunged amid a pricing war between Saudi Arabia and Russia. U.S. oil rose 2.3%.

The energy sector led the S&P 500 higher, rising 6.3%, while oil majors Exxon Mobil and Chevron both added more than 5.5% to boost the Dow industrials.

Gold prices continued to climb, rising 1.2% to $1,838.30 per troy ounce. Investors are buying the metal as a haven asset and to hedge against potential inflation as central banks continue to pump money into the system, according to Luc Filip, head of private banking investments at SYZ Private Banking.

"It's almost a no-brainer, let's buy some gold to hedge when there's many uncertainties still," Mr. Filip said. His company currently holds between 4.5% and 5% of its portfolio in gold.

Silver also continued to climb for the third day, rising 6%. The benchmark price is up 8.4% so far this week.

In Asia, most major equity benchmarks ended the day with muted gains. Hong Kong's Hang Seng Index was among the biggest gainers after it rallied over 2%. Japan's Nikkei 225 rose 0.7%.

Lockheed Martin's shares rose 2% after the defense giant reported that its quarterly revenue and profit were above expectations and revised its full-year outlook higher.

Write to Anna Hirtenstein at anna.hirtenstein@wsj.com