BOSTON — A teenager who sent her boyfriend dozens of text messages encouraging him to take his own life and telling him to “get back in” a truck filled with carbon monoxide fumes must stand trial for involuntary manslaughter, the state’s highest court ruled Friday.

The Supreme Judicial Court ruled that a grand jury had probable cause to indict Michelle Carter, then 17, in the 2014 death of Carter Roy III, 18.

Carter’s attorney had argued that her texts were free speech protected by the First Amendment and didn’t cause Roy to kill himself.

But the court said the grand jury heard evidence suggesting that Carter engaged in a “systematic campaign of coercion” that targeted Roy’s insecurities and that her instruction to “get back in” his truck in the final moments of his life was a “direct, causal link” to his death.

“In sum, we conclude that there was probable cause to show that the coercive quality of the defendant’s verbal conduct overwhelmed whatever willpower the 18-year-old victim had to cope with his depression, and that but for the defendant’s admonishments, pressure and instructions, the victim would not have gotten back into the truck and poisoned himself to death,” Justice Robert Cordy wrote for the court in the unanimous ruling.

The case drew national attention after transcripts of text messages Carter sent to Roy were released publicly, showing her urging him to follow through on his plan to kill himself and chastising him when he expressed doubts.

“I thought you wanted to do this. The time is right and you’re ready, you just need to do it!” Carter wrote in one message.

“You can’t think about it. You just have to do it. You said you were gonna do it. Like I don’t get why you aren’t,” she wrote in another message.

The teenagers had met in Florida two years earlier while visiting relatives. Their relationship largely consisted of text messages and emails. They hadn’t seen each other in more than a year when Roy died, even though they lived only about 50 miles apart in Massachusetts, Carter in Plainville, and Roy in Mattapoisett.

Roy’s grandmother Janice Roy said the family is happy Carter can be put on trial. “He was very vulnerable at that stage,” she said.

Carter’s attorney, Joseph Cataldo, argued that Roy was a depressed teenager who had previously tried to take his own life and was determined to finish the job this time. He said Carter shouldn’t have been charged with manslaughter because Massachusetts doesn’t have a law against encouraging or assisting suicide.

On Friday, Cataldo said he was surprised and disappointed by the court’s ruling. But he noted that the court didn’t weigh in on Carter’s guilt or innocence, but merely found there was enough evidence for the case to proceed to trial.

“At trial, it’s proof beyond a reasonable doubt, which is a much higher standard, and I’m confident that ultimately, after trial, Michelle Carter will be acquitted,” he said.