The presidential campaign of John Edwards was cratering in January 2008 after disappointing finishes in Iowa and New Hampshire.

But he still had one very important bargaining chip: his endorsement.

And he planned to use that endorsement to further his political career, a former top adviser told jurors and a capacity audience in a downtown federal courtroom here Thursday. Edwards envisioned himself in a Supreme Court justice’s robes and was willing to support whichever candidate — Barack Obama or Hillary Rodham Clinton — could make that happen, the former adviser, Leo Hindery, testified.

On the final day of the nearly three-week-long prosecution case against Edwards, Hindery’s testimony provided a compelling glimpse of political bargaining at the highest levels.

The former North Carolina senator is charged with violating campaign finance law by allowing wealthy donors to help him save his political career by paying for a coverup of his extramarital affair with Rielle Hunter, a videographer with whom he conceived a child. Edwards’s attorneys are expected to begin his defense Monday.

Hindery spent weeks trying to negotiate a deal with Edwards’s rivals in the presidential race, he said. The maneuvering began even before the votes were counted in Iowa’s first-in-the-nation caucuses. Hindery said he was summoned to Edwards’s hotel suite, and the candidate pressed him to make overtures to the Obama campaign about his availability to join the ticket as Obama’s running mate, Hindery said. Hindery thought it was too soon, but he agreed to try, launching a search for a phone number to reach his longtime friend and top Obama lieutenant, former Senate majority leader Thomas A. Daschle (D-S.D.), who was vacationing in Mexico.

There was such urgency to get a deal done quickly that later that evening, as Edwards addressed supporters after finishing second in the caucuses, Hindery left the stage to take Daschle’s call, Hindery said. Daschle was less than enthused.

“He thought the timing was inopportune, that it would be difficult to get Senator Obama’s attention” during the victory celebration that night, Hindery testified.

In the coming days, as the campaign shifted to New Hampshire, the Obama campaign was unwilling to commit to having Edwards join the ticket despite Hindery’s continued efforts, and Edwards began to temper his expectations, Hindery said. “If he couldn’t be vice president, he believed he had the qualifications and the ability to serve the administration well as attorney general,” the former adviser told jurors.

At the time of the first overtures to Obama, Edwards was adamantly opposed to having Clinton become the party’s eventual nominee, Hindery said. “He thought that would be a disaster,” Hindery said.

But as the month wore on, Edwards’s position shifted, Hindery said. By the time he was preparing to drop out of the race, in late January, Hindery said, Edwards was gravitating to Clinton and pinning his hopes on her getting the nomination and paving a path for him to the Supreme Court. Later, he would switch again, Hindery said, ultimately endorsing Obama after the future president promised to take on Edwards’s signature issue, poverty.

Prosecutors are trying to convince jurors that Edwards’s ambitions did not end with his candidacy, because some of the payments made by supporters — heiress Rachel “Bunny” Mellon and lawyer Fred Baron — allegedly to cover Hunter’s living costs and keep her quiet were made after Edwards withdrew.

Prosecutors have pounded at Edwards’s credibility, using witnesses to paint him as a serial deceiver. They ended their case Thursday by playing video of Edwards denying that he was the father of Hunter’s child during an ABC interview. By then, the jury had heard many, many times that his statement wasn’t true.