Stocks rebounded on Thursday as strong earnings from major tech companies seemed to ease some of the worries driving a recent wave of selling that had wiped out the market’s gains for the year.

The Standard & Poor’s 500-stock index rose by 1.9 percent, to close at 2,705.57. The rise pulled the stock market back into positive territory for 2018 a day after a turbulent session had erased the last of the year’s gains. Stocks are now up 1.2 percent this year.

The rally on Thursday was a rare upward jolt in what has been a rough run for stocks. Investors have dumped shares over the past month, worried about factors that could threaten the economic and profit outlook for 2019, including the trade war with China, the Fed’s plans to keep raising interest rates and the midterm elections.