The undercover FBI agent who was just yards away from a terrorist attack in Garland, Texas, in 2015 testified in court on Wednesday that he was surprised to see the attack happening.

The agent's testimony came in the federal government's prosecution of Erick Jamal Hendricks, who is accused of recruiting and organizing two other radicalized Islamists to carry out the attack on the "First Annual Muhammad Art Exhibit and Contest" in May of that year. The attack was the first ISIS-backed terror event on U.S. soil.

The undercover agent's role in the attack has been the source of controversy because court filings show he told one of the eventual attackers to "Tear up Texas" in a text message just days after the "Draw Muhammad" event was announced.

The two attackers, Elton Simpson and Nadir Soofi, were residents of Phoenix but drove to Garland for the event, opening fire at a checkpoint on the perimeter of the parking area. Because of the controversy surrounding the event, security was high, and, as a result, Simpson and Soofi were killed within yards of where they began their assault. The ensuing investigation found the pair had several other guns in the vehicle and hundreds of rounds of ammunition.

Besides the "Tear up Texas" message, the undercover agent was also discovered to have been in a separate vehicle that was directly behind Simpson and Soofi's car when the shooting began. After the first shots were fired, the agent tried to flee the scene, but was quickly apprehended by local police.

A security guard, Bruce Joiner, was shot in the leg, and filed a liability suit against the FBI last October in a bid to discover the full level of the FBI's activities and decision making in the lead up to the attack. The suit also accuses then-FBI director James Comey of a cover-up.

"In the aftermath of the attack, former FBI Director James Comey lied to the American people by claiming that Simpson was a needle in a haystack' that was ‘invisible to us,'" the filing claimed. "Even after it had come to light that an undercover FBI agent had been communicating extensively with the terrorists during the week prior to the event and had accompanied them as they carried out the attack, the FBI continued to assert that "[t]here was no advance knowledge of a plot to attack the cartoon drawing contest."

As Joiner's liability case has slowly progressed in the last six months, the government's attorneys have asserted that the "Tear up Texas" text message was "innocuous," and are asking the judge to dismiss the case before discovery can take place.

The recent testimony from the undercover agent in the Hendricks prosecution happened under rare circumstances. In order to keep the agent's identity secure, he was allowed to testify under an assumed name, while also wearing makeup and a disguise. The courtroom was cleared except for the jury, and those who wished to observe the testimony could listen to an audio feed in a nearby overflow room.

The Cleveland Plain Dealer reported that the agent testified he was as surprised as anybody that the attack began that day, but only paraphrased that response. He also testified that he did not know that Simpson and Soofi were going to be in Garland that day.

The Plain Dealer additionally reported that the agent's trip to Garland on the day in question was approved by the FBI, and that the undercover agent "was in contact while there with a Garland police officer assigned to an FBI task force in Dallas."