U.S. stocks surged Friday, finishing just short of record highs, as investors responded enthusiastically to a strong June job market report.

The buying accelerated throughout the day after the Labor Department said U.S. employers added 287,000 jobs last month. That was far more than analysts expected, and after weak reports from April and May, it suggests the economy and job market haven’t run out of steam.

advertisement | advertise on newsday

Mining and materials companies, which would stand to benefit more than other industries from an accelerating economy, took the biggest gains. Machinery makers also jumped. Only eight stocks on the Standard & Poor’s 500 finished lower.

The Dow Jones industrial average surged 250.86 points, or 1.4 percent, to 18,146.74. The S&P 500 rose 32 points, or 1.5 percent, to 2,129.90. The Nasdaq composite advanced 79.95 points, or 1.6 percent, to 4,956.76.

The S&P 500 is less than a point away from the record high it set in May 2015. The Dow, too, is close to a record. They reached those peaks before investors got very worried about the slowdown in China’s economy, before the Federal Reserve started raising interest rates for the first time in almost nine years, and before anyone thought Britain might really vote to leave the European Union.