The numbers: The U.S. created 213,000 new jobs in June, another hearty gain that shows companies are finding ways to fill open jobs despite a dwindling pool of skilled workers.

The gain in hiring topped the 200,000 forecast of economists polled by MarketWatch.

In a surprise, the unemployment rate rose to 4% last month after dropping to an 18-year low of 3.8% in May, the Labor Department said Friday.

The jobless rate rose largely because some 600,000 people entered the labor force. More Americans look for jobs when they are seen as easier to find, another sign the labor market is very healthy.

Related:The unemployment rate rose for a good reason — 601,000 workers searching for jobs

The number of people who were unemployed also grew by half a million, but the increase might be tied to end of the school year when teens enter the workforce.

The shrinking pool of labor is slowly forcing companies to raise pay as the competition for talent intensifies, but they are still managing to keep labor costs down.

Hourly wages rose a modest 5 cents to $26.98. The yearly rate of pay increases was unchanged at 2.7%.

What happened: White-collar professional firms filled 50,000 jobs last month to lead the way in hiring. Manufacturers added 36,000 jobs, health-care providers beefed up payrolls by 25,000 and construction companies hired 13,000 new workers.

The only segments of the economy to reduce employment was retail. Companies shed 22,000 jobs after hiring 25,000 workers in the prior month.

Adding to the bright picture, the government raised the number of new jobs created in May and April by a combined 37,000.

Read: Harley-Davidson isn’t riding off to Europe simply because of the Trump tariffs

Big picture: Many things are going right for the economy and the labor market is at the forefront. Rising sales are cajoling businesses to try to fill a record number of job openings.

The problem is finding enough talent, especially with so many baby boomers retiring. The U.S. has added some 19 million jobs in the last eight years and the unemployment rate could soon drop to levels not seen since the 1960s.

The labor shortage is a double-edged sword, though.

While workers could reap higher pay and benefits, rising labor costs could also spur the Federal Reserve to raise the cost of borrowing more aggressively. That would mean higher payments for mortgages, new cars and other consumer goods.

Read: Why the jobs report is ‘perfect’ for the Fed’s interest-rate plans

Also read:Trump pushes U.S. closer to once-unthinkable trade war. Wall Street’s battered and it could get a lot worse

What they are saying?: “If payroll growth remains anywhere near 200,000, the downward trend in the unemployment rate will return in due course,” said chief economist Ian Shepherdson of Pantheon Macroeconomics. “We still target 3.5% by year-end.”

Market reaction: The Dow Jones Industrial Average DJIA, +0.19% and the S&P 500 SPX, +0.29% rose in Friday trades after investors digested the largely positive employment report.

The stock market has gyrated up and down in the past few months amid worries about a widening trade war, with the U.S. and China each imposing fresh tariffs on Friday. Both indexes have receded from record highs set earlier in the year.

Read: U.S. trade deficit falls 6.6% to 19-month low just before Trump tariffs kick in

The 10-year Treasury yield TMUBMUSD10Y, 0.669% fell to 2.82% owing to the soft wage growth in the jobs report. The modest increase in wages suggests inflation is still well under control.

After reaching 3.1% last month, the yield has also fallen in response to growing trade tensions.