By Anna Hirtenstein and David Benoit

The Dow Jones Industrial Average rose Tuesday, with energy prices and stocks rallying after a new fiscal stimulus package from the European Union provided new hope for fighting the pandemic's economic fallout.

The blue-chip average gained 282 points, or 1.1%, while the S&P 500 rose 0.6%. The Nasdaq Composite slipped 0.1%, a day after a closing at a record.

The energy sector led the S&P 500 higher, rising 6.7%, while major oil companies Exxon Mobil rose 5.6% and Chevron climbed 7.3% to boost the Dow industrials. Chevron on Monday had struck a $5 billion deal to acquire Noble Energy, saying the deal would help it combat the downturn.

The rally carried Brent crude up 2.3%, 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%.

Boosting confidence included some better-than-expected earnings from major U.S. companies and the rising expectations that increased government stimulus around the world would ease the effects of the coronavirus shutdowns.

The European Union reached a historic pact overnight that signaled greater unification and spending across its members. The bloc agreed on 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.3%, paring earlier gains, to its highest close since early March.

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

In the U.S., there are other signs Washington is also moving toward another round of stimulus, though Republicans and Democrats remain split on key issues.

Meanwhile, a busy week of U.S. earnings gave some other signs of confidence.

Shares of Coca-Cola rose 2.7% after the company said revenue fell 28% in the latest quarter as lockdowns to stop the spread of the coronavirus sunk sales of its beverages at restaurants, movie theaters 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.7%, even as other tech giants pared recent gains.

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

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 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%.

The gains in the S&P 500 were widespread, including a 1.2% advance in the materials sector, putting it on pace to move into positive territory for the year, boosted by chemical companies.

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

Financial stocks also were strong, including a 5.8% gain in Wells Fargo shares after the bank announced a new chief financial officer, the latest management change.

Write to Anna Hirtenstein at anna.hirtenstein@wsj.com and David Benoit at david.benoit@wsj.com