The S&P 500 notched a week of strong gains, a reprieve for many investors after a prolonged bout of volatility.

The week was marked by some sharp intraday swings, though for the most part investors got a respite from the heavy selling across markets that has dominated for much of the year.

The S&P 500 inched lower Friday, but it rose 1.9% this week, while the Dow Jones Industrial Average added 0.8%. The tech-heavy Nasdaq Composite jumped 4.6%, and on Friday rose for the fifth consecutive session, notching its longest winning streak of the year.

Some investors have jumped back into the market, looking for bargains after a stretch of volatility that has dragged the S&P 500 down 18% for the year. Many investors returned to a familiar trade in recent sessions: Buying shares of tech companies.

The S&P 500’s technology and communication services groups have been among the biggest winners in recent sessions. Shares of Tesla and chip makers including Micron Technology were among the S&P 500’s best performers for the week, gaining around 10% apiece. The ARK Innovation ETF soared almost 14%. Meanwhile, shares of energy companies, which had been the star performers this year, have lagged behind.

“Everybody we’re talking to right now is looking to add to their equity allocations,” said SJ Zaremba, director at RJA Asset Management. Mr. Zaremba said that some investors were looking to do so through options strategies, so as to not miss out on a potential rebound in the second half of the year.

Investors have been parsing every bit of economic data that has been released in recent days as worries about a recession have grown. Concerns about a potential economic slowdown have rippled through stock, bond and metals markets, driving big swings in everything from Treasurys to copper, the latter which recently fell to its lowest level in nearly two years.

On Friday, the Labor Department’s June jobs report showed that rising interest rates and high inflation are so far not crimping hiring. The U.S. economy added 372,000 jobs in June, well above the 250,000 expected by economists surveyed by The Wall Street Journal.

Some investors said they were encouraged by the pace of hiring, though others said it increased chances that the Fed would proceed with a 0.75-percentage-point increase at its next meeting. The Fed raised interest rates by that much in June, marking its largest interest-rate increase since 1994. The rate hikes have spurred volatility throughout the year and stoked concerns that the moves to combat inflation may tip the economy into a recession.

“On one hand, it’s great to see durable demand for jobs—but pressure on the Fed to hike rates will depress the bulls,” said Mike Bailey, director of research at FBB Capital Partners.

On Friday, the S&P 500 slipped shortly after the opening bell before recovering later in the session, only to give up those gains to end the day.

The S&P 500 lost 3.24 points, or 0.1%, to 3899.38 Friday. The Dow Jones Industrial Average slipped 46.40 points, or 0.1%, to 31338.15. The tech-heavy Nasdaq Composite added 13.96 points, or 0.1%, to 11635.31, continuing its outperformance for the week.

Though the jobs report proved encouraging, other economic data has been disappointing, sending mixed signals to investors. Lately, data have shown a drop in activity in industries ranging from manufacturing to home construction.

A closely watched recession predictor, the yield curve, remained inverted Friday, with the yield on two-year government bonds trading higher than the 10-year equivalent. The yield on the benchmark 10-year Treasury note rose after the monthly jobs report to trade at 3.098%, notching its biggest one-week yield gain in around a month.

The yield on two-year government notes traded at 3.119%, up from 3.039% in the previous session. Yields rise when bond prices fall. 

This week, U.S. central bankers reaffirmed their commitment to fighting inflation, first in minutes from the Fed’s June meeting, and then again on Thursday when two officials signaled support for another 0.75-percentage-point interest-rate increase later this month. Both also indicated that recession fears may be overblown.

Federal Reserve Bank of Atlanta President Raphael Bostic said in a Friday CNBC interview that a 0.75-percentage-point interest-rate increase would be warranted.

The jobs report “gives the Fed a little bit more confidence that it can move aggressively without severely hurting the labor market,” said Mona Mahajan, senior investment strategist at Edward Jones.

But, she added, at some point the hikes “will hit the real economy.”

In corporate news, Twitter shares fell $1.98, or 5.1%, to $36.81 after it said Thursday it would lay off 30% of its talent-acquisition team. They fell around 5% in after-hours trading after Elon Musk said in filings with the Securities and Exchange Commission that he sent a letter to the social-media company terminating his merger agreement to buy it.  

GameStop shares sank $6.58, or 4.9%, to $128.54, after the retailer also said it was cutting staff and terminated its finance chief.

U.S. stocks on Thursday posted their fourth consecutive session of gains.

Photo: Michael Nagle/Bloomberg News

Many expect coming inflation data and the start of second-quarter earnings season next week to bring more volatility.

“There are lots of headfake rallies in a bear market, and I suspect this is one of them,” said Rupal Bhansali, chief investment officer of global equities at Ariel Investments. “There’s a lot more pain to come.”

Elsewhere, the euro has been falling, putting the common currency within striking distance of parity, or equal value with the dollar.

Overseas, the pan-continental Stoxx Europe 600 edged up 0.5%, finishing the week up 2.5%. In Asia, trading was mixed. Hong Kong’s Hang Seng rose 0.4%, while the Shanghai Composite fell 0.2%. In Japan, the Nikkei 225 finished up 0.1%, paring earlier gains following news that former Prime Minister Shinzo Abe was shot during a speech. Mr. Abe later died.

Write to Gunjan Banerji at gunjan.banerji@wsj.com and Caitlin McCabe at caitlin.mccabe@wsj.com.