Shares of health-care stocks gyrated violently Thursday as Wall Street interprets a complex Supreme Court decision that ultimately keeps the vast majority of President Obama’s health-care reform alive.

The ruling had been highly anticipated and forecasts ranged between the entire health-care reform being tossed out to the individual mandate being struck down to it all being upheld.

Ultimately, the court ruled the Affordable Care Act and its individual mandate constitutional, voting 5-4 with Chief Justice John Roberts joining the majority.

The biggest knee-jerk winners in the sector were hospital stocks like Tenet Healthcare (THC) and HCA Holdings (HCA), which leaped in the minutes after the ruling was announced.

Shares of some Medicaid providers such as WellCare (WCG) and Molina (MOH) also enjoyed strong gains. The Supreme Court ruled the Medicaid expansion in the health-care law was unconstitutional because it threatens existing funds to states, and the court opted to make adjustments to this part of the law. 

On the other hand, health-insurance stocks were mixed as UnitedHealth (UNH) and WellPoint (WLP) slumped, but Amerigroup (AGP) soared.

Drug makers outperformed the broader markets as shares of Merck (MRK), Pfizer (PFE) and Bristol-Myers Squibb (BMY) were off less than 1%.

Pharmacy shares saw less volatility, but were also stuck in the red, including CVS Caremark (CVS) and Walgreen (WAG). 

The SPDR health-care ETF was recently trading at $37.17, down 0.8% on the day. The ETF had been at $37.31 in the minutes before the landmark decision was announced.

Meanwhile, the broader markets recently hit session lows in the aftermath of the Supreme Court decision, with the Dow Jones Industrial Average recently off more than 160 points, or 1.3%. The benchmark index had been off about 100 points before the decision was announced. 

Follow Matt Egan on Twitter @MattMEgan5