(CNN) Adapted from " The Chief: The Life and Turbulent Times of Chief Justice John Roberts " by Joan Biskupic. Copyright © 2019. Available from Basic Books.

Chief Justice John Roberts arrived at the Valletta campus of the University of Malta on July 3, 2012, to teach a class on Supreme Court history. As he emerged from the back seat of a black sedan, he held his brown leather briefcase in front of him, almost as a shield. He wore a blue blazer, striped button-down shirt, and tan khakis. His clothes looked crisp, though his face was haggard. He was as exhausted and distressed as he had been in years.

Roberts had left behind a storm in Washington over his opinion upholding President Barack Obama's health-care overhaul -- the Affordable Care Act -- a stunning validation of Obama's signature domestic achievement that transformed public perceptions of the chief justice.

Republicans in Congress had been fighting the law dubbed Obamacare at every turn for two years, and all the GOP presidential candidates in 2012 had vowed to repeal it. And now Roberts, a nominee of President George W. Bush, had saved it.

Going forward, the chief justice would be viewed with skepticism by conservatives, despite also having taken the lead on limiting racial remedies and voting rights, helping roll back campaign finance regulations and voting for stronger Second Amendment gun rights.

Roberts' moves behind the scenes were as extraordinary as his ruling. He changed course multiple times. He was part of the majority of justices who initially voted in a private conference to strike down the individual insurance mandate -- the heart of the law -- but he also voted to uphold an expansion of Medicaid for people near the poverty line.

Two months later, Roberts had shifted on both.

The ACA, signed by Obama in 2010, followed decades of failed attempts in Washington to control spiraling medical costs and provide Americans with higher-quality health care. It created a marketplace where the uninsured could buy coverage and protected people from being unable to get health insurance because of pre-existing conditions such as diabetes, cancer and other chronic illnesses. To support the system and draw in the healthy as well as the sick, the law required that most uninsured people obtain coverage (the "individual mandate") or pay a penalty, to be collected as part of an individual's annual taxes -- a provision critical to the final ruling.

The law also expanded Medicaid benefits to a wider range of needy individuals. The money for about 90% of that expansion would come from the federal government. But it would come with a strict condition: If states did not broaden their programs as dictated they would lose all Medicaid funds.

The first meeting -- 5-4 against the mandate

After an unusual three full days of oral arguments in late March 2012 (a typical case gets one hour on one day), the nine justices gathered in a private conference room off the chief's chambers to cast initial votes. They were alone, with no law clerks or administrative staff.

The discussion focused on the individual insurance mandate and Congress' power to regulate commerce. Roberts went first, as was the custom, laying out his views. He emphasized that he believed the Constitution's commerce clause never was intended to cover inactivity, such as the refusal to buy insurance.

After the chief, conservative Justices Antonin Scalia, Anthony Kennedy and Clarence Thomas offered their views. Like Roberts, they thought Congress' commerce authority did not cover an individual's decision to forgo -- rather than obtain -- health insurance. There were thus four immediate votes cast to invalidate the mandate. No one at the table was surprised, based on the questions during oral arguments and word from law clerks inside the building circulating intelligence among the justices' chambers.

Photos: Chief Justice John Roberts Supreme Court Chief Justice John Roberts listens to President Donald Trump's State of the Union address in January 2018. Hide Caption 1 of 22 Photos: Chief Justice John Roberts Roberts is seen in a yearbook photo from his prep school in La Porte, Indiana. He was born in Buffalo but grew up in northwest Indiana. In 1979, he graduated from Harvard Law School. Hide Caption 2 of 22 Photos: Chief Justice John Roberts Roberts shakes hands with US President Ronald Reagan in 1983. He was an associate counsel to Reagan from 1982-1986. Hide Caption 3 of 22 Photos: Chief Justice John Roberts As an attorney for the government and in 14 years of private practice, Roberts argued 39 cases before the Supreme Court and won 25 of them. Hide Caption 4 of 22 Photos: Chief Justice John Roberts In May 2001, President George W. Bush nominated Roberts to the US Court of Appeals for the District of Columbia. Roberts is seen at right along with Bush's other judicial appointments. Hide Caption 5 of 22 Photos: Chief Justice John Roberts In 2005, Bush nominated Roberts to replace retiring Supreme Court Justice Sandra Day O'Connor. Hide Caption 6 of 22 Photos: Chief Justice John Roberts Roberts, third from left, meets with US senators in Washington a day after he was nominated by Bush. With Roberts, from left, are Sens. Arlen Specter, Bill Frist and Mitch McConnell. Hide Caption 7 of 22 Photos: Chief Justice John Roberts Roberts meets with US Sen. Mary Landrieu as he makes his rounds on Capitol Hill in July 2005. Hide Caption 8 of 22 Photos: Chief Justice John Roberts Roberts was tabbed to replace O'Connor, but plans changed after Chief Justice William Rehnquist died in September 2005. Bush announced that he wanted Roberts to replace Rehnquist instead. Hide Caption 9 of 22 Photos: Chief Justice John Roberts O'Connor weeps as Roberts and other pallbearers carry Rehnquist's casket into the Supreme Court. Roberts was once a law clerk for Rehnquist. Hide Caption 10 of 22 Photos: Chief Justice John Roberts Roberts answers questions during his second day of confirmation hearings in September 2005. The Senate voted 78-22 to confirm him. Hide Caption 11 of 22 Photos: Chief Justice John Roberts Roberts' wife, Jane, holds a Bible as her husband is sworn in by Supreme Court Justice John Paul Stevens. Hide Caption 12 of 22 Photos: Chief Justice John Roberts Roberts and his wife attend his swearing-in ceremony in the East Room of the White House. Hide Caption 13 of 22 Photos: Chief Justice John Roberts The Roberts walk with their children, Jake and Josie, after he took the Supreme Court bench for the first time in October 2005. Hide Caption 14 of 22 Photos: Chief Justice John Roberts Bush enjoys a light moment with Roberts and other Supreme Court justices on Roberts' first day. With Bush, from left, are John Paul Stevens, Ruth Bader Ginsburg, David Souter, Antonin Scalia, Roberts, O'Connor and Kennedy. Hide Caption 15 of 22 Photos: Chief Justice John Roberts Roberts shakes hands with President Barack Obama at Obama's inauguration ceremony in 2009. Hide Caption 16 of 22 Photos: Chief Justice John Roberts Roberts watches Elena Kagan sign the Oaths of Office after she replaced retiring Justice John Paul Stevens in 2010. Hide Caption 17 of 22 Photos: Chief Justice John Roberts Roberts administers the oath of office to President Donald Trump in 2017. Hide Caption 18 of 22 Photos: Chief Justice John Roberts The US Supreme Court, with newest member Brett Kavanaugh, poses for an official portrait in November 2018. In the back row, from left, are Neil Gorsuch, Sonia Sotomayor, Kagan and Kavanaugh. In the front row, from left, are Stephen Breyer, Clarence Thomas, Roberts, Ginsburg and Samuel Alito. Hide Caption 19 of 22 Photos: Chief Justice John Roberts Roberts and Thomas pay their respects to the late President George H.W. Bush as he lies in state in December 2018. Hide Caption 20 of 22 Photos: Chief Justice John Roberts Roberts arrives at the US Capitol to preside over President Trump's impeachment trial in February 2020. Hide Caption 21 of 22 Photos: Chief Justice John Roberts Roberts ends the impeachment trial after Trump was acquitted. Hide Caption 22 of 22

The votes of the liberals were known, too. Justice Ruth Bader Ginsburg, fifth in seniority, was the first to cast a vote to uphold the individual mandate. She believed Supreme Court precedent demanded the law be found constitutional. She was followed by Justice Stephen Breyer, who agreed with her. Next in seniority was conservative Samuel Alito, who cast the fifth and final vote to strike down the law. The eighth and ninth justices at the table, liberals Sonia Sotomayor and Elena Kagan, joined Ginsburg and Breyer in voting for the law as part of Congress' power to regulate interstate commerce.

There was no sign on March 30, 2012, that any of the nine would defy the usual ideological and partisan alignment. That political division bothered Roberts, but he felt just as strongly about boundaries on the commerce power as the other four in the majority did.

Regarding Medicaid, all four liberals voted to uphold the program, and Roberts joined them. At the same time, he expressed some tentativeness.

No vote had been taken related to congressional taxing power. It did not seem to matter, because the individual mandate was going to be struck down. The only uncertainty was whether any of Obamacare would survive.

Roberts did not want the entire law to fall. A pro-business conservative, he understood the importance of the insurance industry to US businesses, and he was genuinely concerned about invalidating an entire law that had been approved through the democratic process to solve the intractable health care problem.

But his four fellow conservatives believed that if the individual mandate was going down, it should take the whole law with it. They believed all the pieces were interlocked. Roberts thought the individual mandate was entwined with only two other provisions, those known as the "community rating" and "guaranteed issue." The community-rating section prevented insurers from charging some individuals higher premiums than others based on health status. The guaranteed-issue section required insurers to cover people regardless of pre-existing conditions.

As was his prerogative as chief justice, Roberts chose to write the majority opinion, giving him the ability to shape what the court would ultimately say. Senior liberal justice Ginsburg was ready to write for the dissenting foursome.

Soon after, Roberts began trying to persuade Kennedy to find that the unconstitutional insurance requirement could be severed from the rest of the law. But Kennedy -- often a swing vote on high-profile cases -- was firm in his position. He was puzzled, and then put off, by Roberts' view that the ACA provisions could be severed.

The deal is struck

Later in April, Roberts tried another path. He began exploring whether, as the Obama administration had argued, the individual mandate could be upheld as a tax. (CBS's Jan Crawford reported earlier on Roberts' reversal on the mandate, but the full story of Roberts' switch, including on Medicaid expansion, and the changed votes of two liberal justices is detailed now for the first time.)

The chief justice then turned to Breyer and Kagan, the liberals most likely to work with him on contentious issues, to see if they could find common ground.

At the same time, Roberts began incorporating arguments that would invalidate the Medicaid expansion. This was a strange turn. None of the lower courts that had taken up the ACA had rejected the Medicaid expansion, and it wasn't seen as controversial in terms of constitutional debate and public controversy.

Roberts posited in a draft opinion that Congress had in effect held "a gun to the head" of the states by conditioning all Medicaid money on the expanded coverage. Yet he was not prepared to find that the expansion had to be scrapped altogether, only that states could not be forced to join through the leverage of losing all Medicaid funding.

Breyer and Kagan had voted in the private March conference to uphold the new Medicaid requirement, and their votes had been unequivocal. But they were pragmatists. If there was a chance that Roberts would cast the critical vote to uphold the central plank of Obamacare -- and negotiations in May were such that they still considered that a shaky proposition -- they were willing to meet him partway.

When Ginsburg found out about Roberts' new position, her first thought was, "It ain't over till it's over." She understood that the process could continue to be fluid, especially in such a monumental case.

"People change their minds about what they thought. So it isn't at all something extraordinary, and that's how it should work. We're in the process of trying to persuade each other and then the public," she told me in a 2012 interview in her chambers.

At the time, Ginsburg knew that Roberts was not deviating from his view of limited commerce clause power, and she wanted to make her dissent as persuasive as possible.

"I was forcing myself to stay awake and work on the opinion," Ginsburg said.

Another complication for Ginsburg was that in late spring she had fallen on the marble floor of her bathroom and cracked several ribs. There was nothing to be done except to work through the pain.

Scalia and the other conservatives were livid at the development. Scalia believed the taxing-power possibility had never truly been discussed in court, calling it a "fly-by-night briefing." Kennedy thought Roberts had presented his interpretation as "judicial modesty," when it amounted instead "to a vast judicial overreaching."

JUST WATCHED Trump fires back after Roberts rebukes him Replay More Videos ... MUST WATCH Trump fires back after Roberts rebukes him 02:57

The announcement

The decision was revealed on June 28, the last courtroom sitting of the 2011-12 session. As Roberts began reading his opinion from the bench, he tried to speak steadily, but he was nervous. About 13 minutes into the 20-minute announcement, after he had summarized various legal rationales, he misstated the overall judgment. Few noticed the slip because he had already laid out the reasoning.

As Roberts spoke, he occasionally looked out at the spectators. Among them was retired Justice John Paul Stevens, who later said he thought the chief had shown integrity.

"He had to be thinking he did the right thing," Stevens said in a 2016 interview in his chambers, "because he certainly made himself very unpopular" with the conservatives.

Perhaps Roberts' move was born of a concern for the business of health care. Perhaps he had worries about his own legitimacy and legacy, intertwined with concerns about the legitimacy and legacy of the court. Perhaps his change of heart really arose from a sudden new understanding of congressional taxing power. However the chief would explain it -- and he has not explained it beyond his written opinion -- the case added a new dimension to a man who insisted that he always decided cases based on the law.

Viewed only through a judicial lens, his moves were not consistent, and his legal arguments were not entirely coherent. But he brought people and their different interests together. His moves may have been good for the country at a time of division and a real crisis in health care, even as they engendered, in the years since, anger, confusion and distrust.

Criticism on the right -- from insiders and outsiders -- was swift, including from the Wall Street Journal editorial page, which described the decision as "shot through with confusion."

Donald Trump, three years from launching his presidential run, went right to Twitter: "Wow, the Supreme Court passed @ObamaCare. I guess Justice Roberts wanted to be part of Georgetown society more than anyone knew."

Trump later added: "John Roberts arrived in Malta yesterday. Maybe we will get lucky and he will stay there."

Wow, the Supreme Court passed @ObamaCare. I guess @JusticeRoberts wanted to be a part of Georgetown society more than anyone knew. — Donald J. Trump (@realDonaldTrump) June 28, 2012