Already, a jury has heard dramatic accounts from C.I.A. officers in disguises and other Americans who survived the attacks. Two other Libyans also provided damaging details about Mr. Khattala as federal prosecutors tried to paint an a damning picture of his activities before and after the attacks.
In his lengthy testimony, Mr. Majrisi talked about how the Americans paid him $5,000 a month to spy on Mr. Khattala and arrange his capture at a seaside cottage about 20 miles southwest of Benghazi. Once Mr. Khattala was in American custody, Mr. Majrisi received the hefty reward, paid in two installments, and was relocated to Texas. He received other compensation from the F.B.I. too, paying for his family’s expenses.
Mr. Khattala’s defense lawyer, Michelle Peterson, suggested Mr. Majrisi’s testimony was financially motivated.
“It’s hard to keep track of all the money the U.S. government was paying you, wasn’t it?” she said. He said it was hard to remember because the events he recounted moved rapidly. Ms. Peterson’s cross-examination seemed to frustrate the informant at times on Tuesday.
Mr. Majrisi provided a pivotal piece of the prosecution’s case: He linked the Benghazi attackers to Mr. Khattala.
As prosecutors played surveillance footage of the attack on the diplomatic compound, Mr. Majrisi identified a number of men and said three were very close to Mr. Khattala. The informant said the men were part of a hit squad that carried out killings on Mr. Khattala’s behalf.
The informant said Mr. Khattala himself could also be seen on surveillance video minutes after the attack began and later at the door of the diplomatic mission, holding an AK-47 assault rifle.
Ms. Peterson asked the informant whether he had special training when it came to recognizing faces on grainy video. He responded he had a “very strong memory.”
Later, Mr. Khattala began sharing incriminating information as the informant gained his trust. He even once showed the informant documents and computers, suggesting the materials had been taken from the diplomatic mission and that he knew the names of Libyans who had visited the American ambassador.
On another occasion, Mr. Khattala showed Mr. Majrisi a mortar and shells he kept in his garage. Mr. Khattala told the informant he was expert in the use of mortars and bragged about his ability to hit targets even under the most difficult circumstances. A mortar was used to attack the C.I.A. base after the diplomatic compound had been overrun, its fire killing two C.I.A. contractors and wounding two other Americans.
Mr. Khattala also spoke of his plans in the attacks, making reference to an American rescue force that had been delayed at the Benghazi airport after arriving from Tripoli.
“I intended then to kill everyone there — even those who were at the airport,” Mr. Majrisi recalled Mr. Khattala saying.
During his testimony, the informant said Mr. Khattala told him the Americans were using a facility to spy on people in Benghazi, a possible reference to the base the C.I.A. had been using.
Mr. Khattala suspected the American government was seeking to arrest him, according to the informant. He testified that Mr. Khattala told a group of militants at a mosque in Benghazi that he was wanted by the Americans.
Mr. Majrisi said that after the capture of an Al Qaeda suspect in October 2013 in Tripoli, Mr. Khattala became paranoid, rarely leaving his house. When he did, he traveled with a group of men for safety reasons. He often changed his phone number and the vehicles in which he traveled.
The informant also said that Mr. Khattala was close to Mustafa al-Imam, who was apprehended late last month in Libya as a suspect in the Benghazi attacks. Mr. Majrisi said Mr. Khattala and Mr. Imam had been imprisoned together in Libya and that Mr. Imam was frequently at Mr. Khattala’s house. He repeatedly identified Mr. Imam on the surveillance video from the attack.
Mr. Majrisi said he began working in Libya with the Americans at the end of 2012, lasting until Mr. Khattala was apprehended in June 2014.
Ms. Peterson said Mr. Majrisi’s American contacts worked for the Defense Department. Former American officials familiar with the operation said that operatives from the military’s Joint Special Operations Command debriefed the informant, instead of F.B.I. agents. Mr. Majrisi said he met with his American handlers every four months.
His secret work, Mr. Majrisi said, was not without risks. He worried about his life. And he had frustrations with the pace of the operation. “It took too long,” he said. “It wore me out, and accompanying him put me under suspicion.”
The informant suggested killing Mr. Khattala himself, “so I can be at rest finally and my city would be at rest, because this person is a murderer.”
But that did not happen. Finally, the Americans designed an operation to capture Mr. Khattala.
“It was a comprehensive plan,” Mr. Majrisi said.
The informant said that the Americans bought a house on the coast, a place where Mr. Khattala would feel safe from rival forces headed by a former C.I.A. asset. One night Mr. Majrisi drove Mr. Khattala to the cottage, where members of the Army’s Delta Force and an F.B.I. agent with the Hostage Rescue Team were waiting. The Americans detained Mr. Khattala while Mr. Majrisi went back to his car. He slept for hours.
He later drove to Tripoli and met with American officials who gave him money. He then made his way to Tunisia and eventually, with the help of the F.B.I., he moved to United States with his family.