They met, sort of, in a New York courtroom in the heat of an attempted murder trial.

He was in the witness box, testifying about gangs, and she was in the jury box — feeling “some type of way,” as she would later explain.

It was the summer of 2017 and Tysheem McGregor, an alleged East Harlem gang member, was on trial for attempted murder in four shootings. He was accused of waging a turf war against a rival gang — one that the witness for the prosecution belonged to.

But as the witness took the stand, helping prosecutors identify McGregor in surveillance footage, Juror No. 6 said her mind wandered. She felt instantly attracted to him, she would later say. So, Juror No. 6 decided to do the one thing she knew was not allowed. She wrote the incarcerated witness a letter confessing her feelings — just as jurors began deliberations.

“I just felt bad for someone who really did try to change their life and then their history caught up after them,” she would later explain to a judge, according to court documents. “And obviously, there was a physical attraction.”

Now, 50 letters later, the courtroom love affair has led a New York appeals court to throw out McGregor’s conviction, saying the romantic relationship made Juror No. 6 inherently biased and deprived 21-year-old McGregor of a fair trial. It wasn’t just letters. There were dozens of phone calls and jail visits and even — finally — a plan to get married.

All of which blossomed before McGregor was sentenced to 15 years in prison later that year.

The witness — identified by the New York Daily News as Xavier Classen — busted the relationship wide open in full view of the court when he told prosecutors and wrote the judge in McGregor’s case, asking for advice on how to obtain a marriage license.

Remanding the case for a new trial, the four-judge panel on New York Supreme Court’s Appellate Division, First Department, called the juror’s misconduct “willful and blatant.” The Nov. 14 ruling was first reported Thursday by the New York Law Journal.

“The juror was admittedly attracted to the witness, a cooperating witness testifying on behalf of the People, and sought to develop a relationship with him while jury deliberations were still underway — even though she knew this was not permitted,” wrote Justice Dianne T. Renwick in the unanimous opinion. “Although the juror denied that her feelings about the witness affected her thinking about defendant, she was at least arguably more likely to credit his testimony and could subconsciously have sought to aide the side with which the witness was aligned.”

The Manhattan District Attorney’s Office could not immediately be reached for comment.

According to the ruling, Juror No. 6 (who is never identified) sent her first letter to Classen on June 26, 2017, during McGregor’s trial. She described who she was in the jury so he would know. And she admitted that she “felt for” Classen, that “seeing you and hearing you up there on the stand made me feel some type of way."

Classen was smitten.

“She said she was one of the jurors and she said she was the blond-headed woman with the bun, which I instantly remembered,” he said during a court hearing about the relationship, the Daily News reported last year.

She left him her phone number and asked him to call. But when he tried her from jail on July 4, 2017, she didn’t pick up, according to the ruling.

That was the day before jurors delivered their verdict.

She returned his call as soon as she could figure out how jail phone calls worked, a couple of days after convicting McGregor ― and the romance escalated quickly.

A few weeks later, Juror No. 6 wrote to a prosecutor asking her to give Classen a reduced sentence in his own criminal case as a reward for his cooperation in the McGregor trial, according to the ruling.

The prosecutor was alarmed.

Classen, on his own, came forward to the prosecutor to disclose their relationship around the same time, and immediately, the prosecutor notified McGregor’s defense attorneys, according to the ruling. McGregor’s sentencing was coming up — and still the courtroom lovebirds didn’t slow down or try to hide the romance.

Classen wrote to the court on Aug. 30, 2017, just days before a scheduled sentencing hearing for McGregor, “asking its assistance in obtaining a marriage license to marry Juror No. 6.”

The judge called a hearing, asking the couple to explain themselves. Juror No. 6 admitted she knew she was not allowed to have any contact with anyone involved in the trial. But she “wasn’t even thinking about any of that at the moment,” because she was “just being a human being making a mistake,” she told the court, according to the ruling.

She had even come to view Classen as unconnected to McGregor’s case. When asked if she understood that Classen’s testimony was “adversarial to the defendant,” Juror No. 6 responded, “In a way. I just didn’t see it like that because to me his whole testimony was like irrelevant to Tysheem’s trial.”

McGregor’s defense attorneys insisted that this juror misconduct was grounds for throwing out the conviction. But Judge Robert Stolz didn’t think so, finding that the relationship didn’t affect the verdict, given the overwhelming amount of evidence against McGregor.

The appeals court, however, disagreed.

The justices pointed to another recent juror misconduct case in New York, in which a 23-year-old cheerleading coach exchanged hundreds of text messages that detailed a murder trial involving a high-profile doctor accused of killing his wife. Even though the appeals court in that case did not find that her text messages were “biased,” the misconduct itself was enough to throw out the murder conviction for the doctor, Robert Neulander.

“As the Court of Appeals recently reminded us in People v. Neulander, ‘nothing is more basic to the criminal process than the right of an accused to a trial by an impartial jury,' ” Renwick wrote.

It’s unclear what became of the steamy courtroom relationship between Classen and Juror No. 6. New York Department of Corrections records show that Classen is serving five years in prison for attempted gang assault. He said during a hearing — before he was sentenced to prison — that all of the drama surrounding McGregor’s trial had put a strain on their relationship and that they decided to break things off, the Daily News reported.

But the appeals court had a sunnier outlook. In the opinion, Renwick suggested they had gotten back together, but it’s unclear how the court knows that or whether it’s accurate.

“The juror is now in a very serious relationship with the witness and seeks to marry him,” Renwick wrote.