By Chuck Mikolajczak

(Reuters) - The S&P 500 and the Dow closed slightly lower on Monday, as a drop in oil prices dragged down energy stocks, while tech names Apple and Alphabet helped lift the Nasdaq to its highest close in over a year.

The S&P 500 had hit a record high earlier in the session, but was unable to hold gains as U.S. crude <CLc1> slumped to below $40 a barrel, its lowest level since April, before settling at $40.06.

"Oil has once again re-emerged as a real driver of how investors are gauging the trend for equities," said Peter Kenny, senior market strategist at Global Markets Advisory Group in New York.

"Now we are beginning to see the glut narrative have an impact on oil and have an impact on equities."

The S&P 500 gained 3.6 percent in July, its best month since March, touching record intraday highs seven times, as the U.S. economy showed signs of picking up and corporate earnings were not as bad as had been initially feared.

Earnings are now expected to decline 3 percent for the second quarter, according to Thomson Reuters data, an improvement from the 4.5 percent decline expected on July 1.

Exxon <XOM.N> and Chevron <CVX.N> were down 3.1 percent and 3.3 percent, respectively, as the biggest drags on both the Dow and the S&P 500. The S&P energy sector <.SPNY> lost 3.3 percent.

The Dow Jones industrial average <.DJI> fell 27.73 points, or 0.15 percent, to 18,404.51, the S&P 500 <.SPX> lost 2.76 points, or 0.13 percent, to 2,170.84 and the Nasdaq Composite <.IXIC> added 22.07 points, or 0.43 percent, to 5,184.20.

The Nasdaq closed at its highest level since July 21, 2015.

Apple Inc <AAPL.O> rose 1.8 percent, providing the biggest boost to the three main indexes. Apple has gained more than 9 percent since reporting results last week. Google parent Alphabet Inc <GOOGL.O> was up 1.2 percent at $800.94.

Data on Monday, however, showed U.S. manufacturing activity slowed in July as orders fell broadly and construction spending dropped in June, following up a tepid reading on U.S. second-quarter gross domestic product on Friday.

Traders saw the chance of a Federal Reserve interest rate hike by year-end at about 35 percent, according to CME Group's Fedwatch, down from more than 50 percent last week.

SolarCity Corp <SCTY.O> fell 7.4 percent to $24.72 and Tesla Motors <TSLA.O> declined 2 percent, to $230.01, after Tesla said the two companies had agreed to merge.

Declining issues outnumbered advancing ones on the NYSE by a 1.46-to-1 ratio; on Nasdaq, a 1.02-to-1 ratio favored decliners.

The S&P 500 posted 37 new 52-week highs and no new lows; the Nasdaq Composite recorded 105 new highs and 21 new lows.

About 6.65 billion shares changed hands in U.S. exchanges, compared with the 6.6 billion daily average over the last 20 sessions.

(Reporting by Chuck Mikolajczak; Editing by Leslie Adler and Meredith Mazzilli)