On the first Monday in October 2003, as the Supreme Court began a new term, a 32-year-old lawyer who then called himself R. Edward Cruz made his first appearance before the justices. It did not go well.

“The justices were ripping me limb from limb,” Sen. Ted Cruz, R-Texas, would later write. “I felt like a chunk of tuna thrown to a school of sharks.”

Cruz had only recently taken a job as the Texas solicitor general — the state’s top appellate lawyer. When he started, he had argued only two cases in any court. But he had a connection to and reverence for the Supreme Court, having served as a law clerk to Chief Justice William H. Rehnquist. A Supreme Court clerkship is one of the most coveted credentials in American law.

Now as a Republican presidential candidate, Cruz emphasizes that connection on the campaign trail, taking particular care to frame the election as “a referendum on the Supreme Court.” He describes himself as the only candidate with the record to nominate conservative justices like Justice Antonin Scalia, who died Saturday.

Cruz: 'Liberty is in the balance'

Cruz routinely rails against what he calls the lawless judicial activism of the Supreme Court led by Chief Justice John G. Roberts Jr., saving special scorn for its decisions upholding the Affordable Care Act and establishing a constitutional right to same-sex marriage.

“This must stop,” he wrote in National Review in June, in an article calling for a constitutional amendment that would strip the justices of their life tenure. “Liberty is in the balance.”

Speaking in South Carolina on Monday, he described his two-decade relationship with Scalia — the “voluble Italian” as he described him — with favorite tales of his judicial prowess and wit.

At that first argument, though, the relationship looked rocky.

An early loss to Scalia

Cruz was making a states’ rights argument. Texas had agreed to settle a federal lawsuit accusing it of denying medical treatment to children, a violation of federal Medicaid requirements. But Cruz said the state had the constitutional authority to ignore the settlement, one that had taken the form of a consent decree.

Scalia was not convinced. “Why would the other side ever accept such a consent decree?” he asked. “It’s crazy.”

Cruz lost, 9-0.

He argued eight more cases before the court. As time went on, he grew more polished and won significant victories, though he had trouble capturing the often crucial vote of Justice Anthony M. Kennedy.

Building a conservative profile

If Cruz was more apt to debate than to persuade, that was part of his plan. He used his five years as solicitor general, from 2003 to 2008, to build an office dedicated to pursuing conservative principles and to elevate his public profile. He argued cases on the death penalty, voting rights and international relations, and he filed supporting briefs defending gun rights and the Pledge of Allegiance.

Today, the office is involved in almost every major Supreme Court case this term, with Texas’ current solicitor general, Scott A. Keller, directing the state’s attack on President Barack Obama’s immigration plan and defending its restrictive abortion law.

Scalia’s death has complicated matters, raising the prospect of 4-4 ties that would automatically affirm appeals court decisions without setting Supreme Court precedents.

Boots required

Keller said Cruz was a mentor who was by turns driven and self-deprecating, and who was fond of saying that “every case is really about a story.”

Cruz jokingly blamed his former boss, Rehnquist, for his defeat in his first Supreme Court appearance. The chief justice, Cruz said, was “a stickler for wardrobe,” once criticizing a lawyer for wearing a brown suit. Fearing a similar rebuke, Cruz had set aside his “lucky black ostrich argument boots” in favor of a “a pair of old wingtips.”

When Roberts replaced Rehnquist as chief justice in 2005, Cruz asked him whether he could wear his boots to court. “When representing the state of Texas,” the new chief justice said, as Cruz recalled in his memoir “A Time for Truth,” boots “are not only appropriate, but required.”

'Jump in whenever you want'

Lawyers who faced Cruz said he moved easily in the clubby world of the elite Supreme Court bar, was generally collegial and was poised in handling the barrage of questions the justices trained on him.

“The image you get of him as a senator sort of shaking things up and not following the rules, you don’t get that sense of him at all in this capacity,” said Paul M. Smith, who argued against Cruz in a 2006 voting rights case. “He knew the rules and played by them.”

Still, Cruz could get lost in the crosstalk among the justices.

“Jump in whenever you want,” Roberts told Cruz in the voting rights case during an extended exchange between Scalia and John Paul Stevens.

Once a fan of John Roberts

Cruz supported Roberts’ nomination in 2005 but has since had harsh words for him and says he would not have nominated him had he been president. But Cruz was a fan of the chief justice’s work as a lawyer, calling him the best Supreme Court advocate of his generation.

“I worked hard to try to emulate his argument style,” Cruz wrote of Roberts’ 39 appearances before the court. “With his immense credibility before the court,” Cruz wrote, “Roberts had consistently managed to get the swing votes to sway in his direction.”

In dissent, Kennedy calls out Cruz

Cruz had less luck in reaching the court’s current swing vote, Kennedy, just as he sometimes fails to connect with other moderate Republicans.

Kennedy wrote the majority opinion rejecting Cruz’s arguments in his first outing. He was the sole dissenter in a ruling Cruz won in a patent case. And he was the decisive vote against Cruz in a series of 5-4 decisions.

Kennedy grew instantly agitated during Cruz’s second appearance before the court. The question in the case was what to do about a thief named Michael Wayne Haley, who had been mistakenly sentenced to almost 15 years more than the law allowed.

“You’ve conceded that this sentence is unlawful?” Kennedy asked. Cruz said yes, but he added that the defendant had failed to object to the mistake in time.

By now Kennedy was sputtering. “I just don’t understand why you don’t dismiss this case and move to lower the sentence,” he said.

Cruz, sensing another defeat, changed tactics. “It became apparent at the oral argument that there were not five votes to keep Mr. Haley incarcerated,” he told The Texas Tribune in 2012. “I would regularly talk to my students about the Haley case as a good example of how an advocate can rescue victory from the jaws of defeat.”

Cruz suggested that the court could sidestep the timing question and direct the appeals court to determine whether Haley’s lawyers had failed to represent him effectively. And he agreed that Haley could remain free in the meantime.

Six justices accepted his invitation, and Haley eventually won on the alternate ground. But Kennedy was still steaming, writing a dissent that chastised Cruz for elevating legal abstractions over human decency and ordinary fairness.

Death penalty case

Cruz also lost Kennedy’s vote in a high-profile death penalty case in which Cruz argued that the Constitution allowed the execution of child rapists.

Cruz tallied the jurisdictions that allowed the punishment, a point designed to appeal to Kennedy, saying that seven state legislatures had authorized it.

But Cruz overlooked recent revisions to the Uniform Code of Military Justice, a federal law, that also seemed to allow the death penalty for child rape, missing a helpful point in his favor. The law “eluded everyone’s research,” he told The New York Times after the mistake came to light.

Kennedy, writing for a five-justice majority, relied in part on the assertion that federal law did not allow the punishment to rule that murder is the only crime against persons that warranted the death penalty. Four months later, Kennedy revised his opinion, but said “the military penalty does not affect our reasoning or conclusions.”

A 'profound' victory in 2008

Cruz’s biggest triumph at the Supreme Court came in 2008 in Medellin v. Texas, in which he successfully outflanked the Bush administration from the right. The case arose from a ruling by the International Court of Justice in the Netherlands ordering new hearings for 51 Mexicans on death row in the United States.

The decision required U.S. courts to grant “review and reconsideration” to claims that the inmates’ cases had been hurt by the failure of the local authorities to allow them to contact consular officials, as required by the Vienna Convention.

The Bush administration had agreed to be bound by the international court’s rulings on the convention, and President George W. Bush, known for his general hostility to international institutions and for his support for his home state’s death penalty, nonetheless instructed states to abide by the international court’s ruling.

Texas refused, saying Bush had violated the separation of powers and principles of federalism. In an article last year in The Harvard Journal of Law & Public Policy called “The Obama Administration’s Unprecedented Lawlessness,” Cruz said Bush’s directive in the Medellin case was of a piece with that lawlessness, one that “exemplifies executive overreach.”

Cruz gave a polished and confident argument in the Supreme Court in the Medellin case, and he won, 6-3. The case is taught in law schools and featured in Cruz’s campaign ads.

“The Medellin victory was profound for me,” Cruz wrote in his memoir.