In closing arguments in a trial that has veered off script, the fallen politician drops a bombshell: that the key government witness was in love with Bo's wife.

BEIJING — The trial of a fallen comrade, Bo Xilai, was supposed to be a morality play hyping the Chinese Communist Party's determination to fight political corruption.

Somewhere the proceedings veered off script, potentially backfiring for President Xi Jinping, who was elevated to the party leadership last year after a power struggle with Bo's faction.

Bo's tenacious defense in the trial caught Chinese prosecutors and the state media off-guard. In the closing arguments Monday, he upstaged the prosecution by dropping a bombshell, saying the key government witness, whistle-blower and former Police Chief Wang Lijun, had been secretly in love with Bo's wife.

Conducting much of his own defense despite his lack of legal training, Bo let drop personal tidbits about his strained relationship with his wife and two sons, one from an earlier marriage. To emphasize his disinterest in money, he confided in his closing statements that "the long johns I still wear were bought for me by my mother in the 1960s."

Although prosecutors proved that Bo's wife, Gu Kailai, had accepted plane tickets and gifts worth $4 million from businessmen, they were never able to demonstrate that Bo knew or that he had promised political favors in return for bribes.

To the extent public opinion can be gauged in China, Bo appears to have acquitted himself among the public at large, perhaps salvaging his political legacy, if not his future.

Zhang Lifan, a party historian in Beijing, said the 64-year-old Bo might end up with a harsher sentence as a result of his courtroom performance but that he was more interested in how he is remembered. "He wants to go out as a hero. If he can't come back politically, he at least wants to ensure his place in history as the spiritual leader of the left wing in China," Zhang said.

Alan Zhang, a critic of Bo's in Chongqing, where the defendant served as Communist Party secretary until his downfall last year, acknowledged that he felt some sympathy for Bo.

"Bo's defense in the trial won him more support in Chongqing. People felt he did a lot of things for the city and that he was not that corrupt by the standards of Chinese politicians. The amount of money he took was relatively small."

The trial took place in Jinan, 250 miles south of Beijing. Before it started, state television announced it would conclude within two days, more than the standard length for a Chinese trial. Instead, it turned into a contentious five-day affair.

Political analysts believe that a deal was cut in advance under which Bo would be allowed to speak out in his own defense in return for acknowledging the accusations against him and apologizing. However, Bo shocked the prosecutors by recanting signed confessions he had made to Communist Party disciplinary inspectors.

"Bo shocked a lot of people. They thought he was going to say 'yes' to all the charges, and instead he denied everything," said a lawyer who is a family friend and familiar with the case. "The prosecutors weren't prepared. They didn't have enough evidence."

Zhang, the party historian, said he also believes that Bo engaged in some mischief-making in order to get revenge against his persecutors. "He is a troublemaker. He broke with the original plan, and now there is going to be a big fight within the leadership about how to sentence him. That might only escalate the power struggle."

Under the Communist Party system, there are seldom juries. Judges mete out sentences that are usually dictated from above, according to lawyers.

The state media have reported that Bo will be sentenced in September.

Bo was charged with accepting bribes; embezzling money from the city of Dalian, where he used to be mayor; and abuse of power.

The last charge comes from Bo's alleged attempt to cover up an investigation into the November 2011 murder of Neil Heywood, a British expatriate who had handled real estate in Europe for the family. Gu, Bo's wife, was found guilty last year of poisoning Heywood out of fear that he would expose her overseas wealth.

The murder case, which triggered Bo's downfall, became public in February 2012 when Wang, police chief in Chongqing, fled to a U.S. Consulate and sought political asylum, saying he feared for his life after uncovering the murder.

Bo stunned the court Monday in the final moments of his closing arguments when he said Wang had sought asylum at the consulate because of his love for Gu.

"He hurt my family. He hurt my feelings. This is the real reason for his defection," Bo told the court.

Bo claimed he had walked in on Wang presenting a letter to his wife in which he had confessed his love. Wang, he said, was so distraught that he slapped himself in the face.

The revelations were among the salacious details that turned the trial into something of a tragicomedy. Earlier in the proceedings, Bo confessed that he had been having an affair in the 1990s, which prompted Gu to move to Britain with their son. As a result, Bo said, he wasn't aware that Chinese businessmen were giving her expensive gifts, including a $3.3-million villa on the French Riviera.

"For 10 years Gu Kailai had been hiding things from me," Bo told the court in a confessional mood. "She should have come to me. I'm her husband."