NEW YORK - The U.S. stock market ended slightly lower Tuesday, avoiding the sharp declines in Europe and Asia thanks to a rally in beaten-down energy companies.

After an early sell-off, the Dow Jones industrial average steadied and ended with a moderate loss of 0.29 percent. That followed a sharp drop in European indexes, most notably in Greece, where the stock market suffered its biggest one-day loss since 1987. Greek officials called an early presidential vote, and investors feared the outcome could jeopardize the country's bailout program.

Stocks in China also stumbled, interrupting a months-long surge, after regulators there tightened rules for lending.

At the end of the day, the Dow lost 51.28 points, or 0.29 percent, to close at 17,801.20. It was down as much as 222 points in early trading. The Standard & Poor's 500 index closed effectively unchanged on the day, down 0.49 of a point to 2,059.82. The Nasdaq composite added 25.77 points, or 0.54 percent, to 4,766.47.

Energy companies were among the best performers, helped by a rebound in oil prices from a five-year low. Six out of the 10 biggest advancers in the S&P 500 were oil and gas exploration companies. The gains in the energy industry were a respite for a sector that has been hit hard this year. The S&P 500 energy index is down 12 percent in 2014, vs. the 11 percent rise in the overall market.

Telecom companies were among the biggest decliners Tuesday. Verizon fell $1.98, or 4 percent, to $46.92. Verizon said its wireless division's recent practice of deep discounting and buying out competitors' contracts could hurt its profit margins. AT&T, another major wireless carrier, dropped 99 cents, or 3 percent, to $32.89.

Major Chinese oil and bank stocks fell, some by the daily limit of 10 percent allowed by regulators, after China's clearing house for securities trades raised the minimum rating for corporate bonds it would accept in exchange for short-term credit. That prompted concerns about the availability of financing for trades.

The price of oil rose as the value of the dollar fell. Because oil is priced in dollars, a weaker dollar makes oil more attractive to global investors. Benchmark U.S. crude rose 77 cents to close at $63.82 a barrel on the New York Mercantile Exchange. Brent crude, a benchmark for international oils used by many U.S. refineries, rose 65 cents to close at $66.84 on the ICE Futures exchange in London.

The price of gold rose $37.10, or 3.1 percent, to $1,232 an ounce. Silver jumped 86 cents, or 5.3 percent, to $17.13 an ounce and copper rose four cents, or 1.5 percent, to $2.93 an ounce.