This courtroom sketch depicts Ahmed Abu Khattala listening to an interpreter through earphones during the Oct. 2 opening statement by Assistant U.S. Attorney John Crabb, second from left, in U.S. District Court in Washington. (Dana Verkouteren/AP)

The government's effort to prove Ahmed Abu Khattala responsible for the September 2012 attacks on U.S. facilities in Benghazi, Libya, after days of wrenching testimony by victims, has turned to a witness who for the first time directly implicated him in planning the assault.

A Libyan military commander said in recorded video testimony played to jurors Thursday and set to continue Monday that a year before the terrorist attacks that killed U.S. Ambassador J. Christopher Stevens and three other Americans, he heard Abu Khattala “incite” dozens of revolutionaries at a meeting in Benghazi by speaking out against an alleged U.S. intelligence post operating out of a diplomatic mission in the city.

The commander, testifying under the pseudonym Khalid Abdullah for his and his family’s safety in Benghazi, added that days before the attacks, Abu Khattala told him of his plan and asked for armed vehicles, which the commander said he took as a message to his roughly 400-man force not to interfere.

The officer’s testimony did not go entirely smoothly for the prosecution, as his credibility, motivation and actions came under harsh challenges from the defense team. In testimony set to be played Monday to the jury, the commander defends Facebook posts that allegedly show his bias and lethal excess against Islamist militants.

The unusual circumstances of his appearance — recorded at the U.S. Embassy in Cairo in July — underscored the security challenges of gathering and presenting evidence amid the bloody civil war in Libya and shifting political alliances.

Members of Libyan special forces loyal to Khalifa Hifter, shown honored on a billboard, patrol the streets of Benghazi on Sept. 19, 2017. (Abdullah Doma/AFP/Getty Images)

Abu Khattala is the sole person to go to trial in a U.S. courtroom in the terrorism case over night-long attacks Sept. 11 and 12, 2012, in which militants overran and burned a State Department special mission about 10 p.m. and hit a nearby CIA annex with mortars after 5 a.m. The four Americans were killed in the assault.

He has pleaded not guilty to 18 charges filed after his June 2014 capture in Libya by U.S. commandos.

Prosecutors say that while others participated in the attacks, Abu Khattala told individuals that he masterminded the affair, directed underlings at the mission, and delivered training and maps that made the precision mortar attack possible.

Defense lawyers counter that Abu Khattala is merely an outspoken militia leader scapegoated by Libyan power brokers to shield others in their ranks against whom the U.S. government has evidence.

The defense team notes that influential Islamist militias other that Abu Khattala's played a role in the attacks, such as the February 17 Brigade, which the U.S. government paid to protect its facilities, and that all of them have contended in a violent political power struggle with Abdullah's secular, Egyptian-backed Libyan National Army, now rising and led by Gen. Khalifa Hifter.

Hifter, a former CIA asset who spent years in exile in Northern Virginia, launched his anti-Islamist "Operation Dignity" offensive the month before Abu Khattala's capture by U.S. commandos in June 2014.

Ahmed Abu Khattala was photographed shortly after his apprehension by U.S. Special Forces near a villa south of Benghazi, Libya, on the evening of June 15, 2014. (U.S. Attorney's Office for the District)

The commander and his allies “will do, say anything to get their enemies, and whether they can kill him [Abu Khattala] on the battlefield, or have him locked away in the United States, their mission would be accomplished,” defense attorney Jeffrey D. Robinson told jurors.

The commander was the first witness to allege that Abu Khattala conspired in the attacks and the only one so far to testify to events before the attacks took place. The trial, which began Oct. 2, poses a high-profile test of U.S. counterterrorism policies developed in recent years to capture terrorism suspects abroad and interrogate them for intelligence purposes, while preserving the right to prosecute them in U.S. civilian court.

The commander’s video deposition was played to jurors after U.S. District Judge Christopher R. Cooper in Washington issued opinions last week explaining that in March 2015 he had granted prosecutors’ request to take the commander’s sworn testimony before the trial started because the witness could be killed before the case came to a courtroom.

Cooper wrote that in June he granted a second request by prosecutors to take the deposition overseas, because the commander was unable or unwilling to travel to the United States for security reasons.

The commander was deposed over seven hours on July 28 at the U.S. Embassy in Cairo, in the presence of an interpreter, lawyers from both sides and counsel of his own, with the judge participating by live video link from Washington.

Abu Khattala and additional lawyers from his defense team observed in Washington and could communicate with their colleagues in Cairo by phone.

The proceeding was videorecorded, and more than four hours of the session were played to jurors Thursday, with another 1 1/2 hours to be played Monday. A full transcript of the proceeding was unsealed Friday.

The commander, a 44-year-old father of five from Benghazi who served briefly in the military under dictator Moammar Gaddafi in the 1990s, said in testimony played Thursday that in 2012 he commanded a Libyan National Army unit called Security Support for Military Intelligence that had been formed in 2011 against Gaddafi.

In 2011, the commander said, he attended a meeting of dozens of “revolutionaries” where Abu Khattala accused the United States and Red Cross of spying from their facilities.

“ ‘As revolutionaries, how can we allow the presence of intelligence, a foreign intelligence entity amongst us in Benghazi?’ ” Abu Khattala asked, according to the commander’s testimony. “He was inciting the people.”

In September 2012, Abu Khattala appeared at the door of the officer’s home, where the two spoke alone, he said. Abu Khattala asked for equipment from the officer’s 370- to 400-man unit, he said in the recording played in court.

“ ‘I want you to provide me with military cars, armed cars,’ ” the commander quoted Abu Khattala as saying. “He said he wanted to attack the American consulate.”

The commander testified that he did not expect Abu Khattala to follow through with an actual attack, did not discuss timing or details, and did not provide any equipment. But he took the request as a message to the army. “Don’t allow your men to interfere during the attack,” he said under questioning by Assistant U.S. Attorney Julieanne Himelstein.

Under cross-examination by defense attorney Michelle M. Peterson, however, he admitted that his recollection had changed since his initial statement to the government — by adding mention of the Red Cross and dropping a claim that Abu Khattala had told him an attack was imminent during their talk at the commander’s home. He also testified that he told no one about Abu Khattala’s alleged involvement before the attacks, and did not speak with Americans until October 2014.

The commander said that others knew his account earlier and that a brother of his was separately speaking with Americans. But he acknowledged that he directly spoke with American investigators only after one of his brothers had been kidnapped and killed and another had been wounded in an assassination attempt by Islamist “terrorist organizations.”

At that point, his family also was in talks that eventually resulted in about 10 members of the extended family being allowed to move to the United States and the U.S. government’s paying $170,000 to cover those relatives’ expenses.

The commander testified that his wife and children, however, lived in Egypt for much of the past three years before returning to Benghazi, where he and they remain.

“How can you put a value on the testimony that I will be giving?” an agitated and combative commander said at one point when Peterson questioned his motivations.

“I did not come here except to present the case of those who met their fate, died, at the embassy during the attack. Nobody forced me to come or made me come,” he said at another point in the testimony played Thursday.

According to the unsealed transcript of the Cairo session, jurors Monday are set to hear of other acts in Libya by the commander, and his response to questioning about specific social-media posts and whether they show him endorsing extrajudicial killings or wounding of terrorism suspects.

The transcript from the Cairo session scheduled to be played Monday in court has the commander acknowledging that in one social-media post in Arabic that appeared under his real name, he wrote, “The real meaning of to tread underfoot,” next to a photograph of an armed soldier standing atop the bodies of two dead militants.

Referring to Abu Khattala, the commander said “he’s well-known that he is takfiri,” and “a leader of terrorist groups and organizations” that are “well-known to have killed and slaughtered people,” according to a part of the deposition set to be played Monday. The reference uses the Arabic word for a Muslim apostate, a term extremists groups have invoked to justify the execution of moderate opponents and which some mainstream leaders have adopted in referring to armed extremist groups.

“You have decided that Mr. Abu Khatallah is a bad person before you came in here today, didn’t you?” Peterson, the defense lawyer, asked in the transcript, saying there was “no greater bias” than the commander’s conclusion Abu Khattala is a terrorist.

“Why would the United States grab Abu Khatallah in Libya? Because he is a good man?” the commander replied.

The U.S. government alleges that the Benghazi attacks were carried out by members of Ansar al-Sharia, a U.S.-designated terrorist group that seeks to establish Islamic law in Libya and includes a component known as Ubaydah ibn al-Jarrah that Abu Khatalla commanded.

The commander in his testimony identified Abu Khattala as one of several terrorist enemies that Hifter’s forces have battled, along with leaders of the February 17 Brigade.