US stocks have broken a two-day losing streak as investors bought up drug-makers and other health care companies.
Energy companies also jumped as the price of oil surged.
Biotech drug companies, which have been mired in a long slide, made their biggest gains in almost five years.
This came after Pfizer ditched a plan to buy Botox maker Allergan for 160 billion dollars (£112 billion), with investors wondering if it will look elsewhere.
The gains were only enough to wipe out most of the market's losses from a day earlier. Stocks have wavered in recent weeks as investors wait for quarterly earnings to start pouring in, and many are braced for another shaky quarter.
The Dow Jones industrial average gained 112.73 points, or 0.6%, to 17,716.05. The Standard & Poor's 500 index rose 21.49 points, or 1.1%, to 2,066.66. The Nasdaq composite index picked up 76.78 points, or 1.6%, to 4,920.72.
Pfizer and Allergan confirmed they are walking away from their proposed merger after the US Treasury Department announced new rules that made the deal, and others like it, far less appealing. Pfizer rose 1.57 dollars (£1.10), or 5%, to 32.93 dollars (£23), its biggest gain since 2011.
Pfizer was ready to make one of the largest corporate deals in history for Allergan as it tried to boost its sales and cut its tax bill. Biotechnology companies, which make complex and costly drugs, climbed higher. Celgene, which makes treatments for cancer, gained 6.10 dollars (£4.30), or 6%, to 108.22 dollars (£76). Vertex Pharmaceuticals rose 7.15 dollars (£5), or 8.5%, to 91.31 dollars (£64).
Biotech stocks are facing pressure from legislators over the price of their drugs, and investors fear that their ability to raise prices will be impeded.
Energy companies gained ground as benchmark US crude rose 1.86 dollars (£1.30), or 5.2%, to close at 37.75 dollars (£26.50) a barrel in New York. Brent crude, a benchmark for international oils, added 1.97 dollars (£1.38), or 5.2%, to close at 39.84 dollars (£28) a barrel in London. The price of oil has skidded in recent days before making small gains on Tuesday.
Chevron picked up 2.17 dollars (£1.52), or 2.3%, to 94.84 dollars (£66.70) and Exxon Mobil added 1.10 dollars, or 1.3%, to 83.31 dollars (£58.60). Hess rose 2.74 dollars (£1.92), or 5.3%, to 54 dollars (£38).
Oilfield services companies Halliburton and Baker Hughes also traded higher after the US government sued to block them from combining.
Halliburton had agreed to buy its rival for more than 34 billion dollars (£24 billion) in November 2014, after oil prices began to fall. Baker Hughes gained 3.47 dollars (£2.44), or 8.8%, to 42.83 dollars (£30). Halliburton climbed 2.04 dollars (£1.43), or 5.9%, to 36.44 dollars (£25.60).
Motorcycle firm Harley-Davidson took the biggest loss on the S&P 500, as it gave up 3.50 dollars (£2.46), or 7%, to 46.34 dollars (£32.60). Analyst John Tomlinson of ITG Investment Research said he thinks the motorcycle company lost market share over the first three months of this year, and said he thinks its retail sales in the US will drop in the first quarter.