EDINBURG — A state’s witness undid nearly two years of preparation in a gang-related murder trial after she violated a rule meant to keep her from tainting testimony, causing a mistrial.

District Judge Keno Vasquez, in his first high-profile murder trial as a judge, declared a mistrial Thursday after he agreed with the defense’s assertion that her violation would hinder their ability to provide a fair trial for their client.

A day after she testified that Jorge Alberto Guajardo admitted to his involvement in a gang-related shooting on Expressway 83 that left a teen dead, Shaniqua Jazzel Silva narrowly escaped jail time of her own after she admitted to posting articles and comments on social media related to her testimony in the case — a violation of a court order for all witnesses not to discuss the case.

“Do you know what you’ve done?” Vasquez said aloud in Silva’s direction.

The 21-year-old woman claimed during testimony Wednesday to be Guajardo’s best friend, and answered the state’s questions for nearly two hours where she told jurors that Guajardo confessed to her that he and others shot at Javier Olmedo and other rival gang members because they disrespected him and his gang.

The dramatic turn of events took place Thursday morning in a case that shifted favorably for the state late Wednesday after Silva’s testimony placed Guajardo at the shooting — the only witness up to that point in the trial to do so.

Silva, who was told twice Wednesday before she left the stand after more than two hours of testimony not discuss the case with anyone, admitted during the defense’s cross-examination of her Thursday morning that she posted comments and was tagged by others in articles related to the case less than four hours later.

In another social media post, which the defense presented in court, Silva also stated she ingested synthetic marijuana, or Spice, prior to her testimony Wednesday — a post she said was a lie because she believes she’s five months pregnant.

The state, represented by Vance W. Gonzales, Michelle Puig, and Mauricio Martinez, eventually agreed that the chances of the case coming back on appeal because of this rule violation was enough for them to go along with a mistrial.

Based on the discovery, Guajardo’s defense attorneys, Christopher Sully and Alejandro Ballesteros, asked the court to declare a mistrial, which Vasquez granted.

Vasquez, after initially threatening to find Silva in contempt of court for her actions, told the Donna woman that he would spare her due to her alleged pregnancy despite a push from Ballesteros to have her jailed.

Vasquez said that if it is true Silva is pregnant, her incarceration would only further burden Hidalgo County taxpayers, who have already footed the bill for trial’s proceedings up to this point.

Vasquez said the trial would begin as soon as they set a new trial date — saying he would give the nearly two-year case priority — possibly in August.

Guajardo, who has been in custody at the county jail since late October 2015, walked out of court accompanied by his attorneys Thursday afternoon knowing the process for his trial will begin anew.

If and when the case goes back to trial, Guajardo faces up to life in prison.