Wall Street closed out the final day of the second quarter with slight gains after a broad rally faded in the last few minutes of trading Friday.

The Dow Jones industrial average and the Standard & Poor’s 500 index eked out tiny gains, while the Nasdaq composite closed essentially flat.

advertisement | advertise on newsday

Industrial stocks and consumer-focused companies led the gainers. Energy stocks also rose as crude oil prices closed higher for the seventh straight day. Utilities, technology and health care companies were among the biggest decliners.

Trading was mostly subdued ahead of the Independence Day holiday next week, though many investors seized on the final trading day of the quarter and the previous day’s market slide to buy more shares or close out positions and book profits.

“Overall we’re ending this quarter with a strong market, even though technology has taken a hit, other sectors have moved up,” said Quincy Krosby, chief market strategist at Prudential Financial.

The S&P 500 index rose 3.71 points, or 0.2 percent, to 2,423.41. The Dow gained 62.60 points, or 0.3 percent, to 21,349.63. The Nasdaq lost 3.93 points, or 0.1 percent, to 6,140.42. The Russell 2000 index of small-company stocks gave up 0.84 points, or 0.1 percent, to 1,415.36.

Bond prices fell. The 10-year Treasury yield rose to 2.30 percent from 2.27 percent late Thursday.