TAUNTON, Mass. — A young woman who sent a barrage of text messages to another teenager urging him to kill himself was found guilty Friday of involuntary manslaughter in a case that many legal experts had expected to result in an acquittal.

The verdict, handed down by a judge in a nonjury trial, was a rare legal finding that, essentially, a person’s words alone can directly cause someone else’s suicide.

The judge, Lawrence Moniz, of Bristol County Juvenile Court in southeastern Massachusetts, said the conduct of the woman, Michelle Carter, toward Conrad Roy III was not only immoral but illegal. Ms. Carter, who faces up to 20 years in prison, will be sentenced on Aug. 3.

Ms. Carter was 17 in July 2014 when she encouraged Mr. Roy, 18, whom she called her boyfriend, to kill himself. On July 12, while she was miles away, he drove alone to a Kmart parking lot and hooked up a water pump that emitted carbon monoxide into the cab of his truck. When he became sick from the fumes and stepped out, prosecutors said, Ms. Carter ordered him by phone to “get back in.” He was found dead the next day.

Knowing that Mr. Roy was in his truck and in a toxic environment, the judge said, Ms. Carter took no action.

“She admits in subsequent texts that she did nothing, she did not call the police or Mr. Roy’s family,” Judge Moniz said. “And finally, she did not issue a simple additional instruction: ‘Get out of the truck.’”

The verdict came as a surprise to many legal experts, because suicide is generally considered, legally, to result from a person’s free will.

Judge Moniz acknowledged that Mr. Roy had taken steps to cause his own death, like researching suicide methods, obtaining a generator and then the water pump with which he ultimately poisoned himself. Indeed, Judge Moniz said that Ms. Carter’s text messages pressuring him to kill himself had not, on their own, caused his death.

But then, Judge Moniz homed in on the cellphone calls between Ms. Carter and Mr. Roy while he was poisoning himself in his car. At the time, he said, Mr. Roy had fearfully climbed out of the car.

“He breaks that chain of self-causation by exiting the vehicle,” Judge Moniz said. “He takes himself out of that toxic environment that it has become.”

Judge Moniz pointed out that, during previous suicide attempts in 2012, Mr. Roy had second thoughts and reached out to friends and family for help. But, the judge said, Mr. Roy did not get help when he talked with Ms. Carter.

“She instructed Mr. Roy to get back into the truck, well knowing his ambiguities, his fears, his concerns,” Judge Moniz said. “This court finds that instructing Mr. Roy to get back in the truck constituted wanton and reckless conduct, by Ms. Carter creating a situation where there is a high degree of likelihood that substantial harm will result to Mr. Roy.”

As he finished, Judge Moniz asked Ms. Carter, who was sobbing, to stand. He then concluded: “This court, having reviewed the evidence, finds you guilty on the indictment with involuntary manslaughter.”

A spectator let out an audible “wow” as the judge pronounced her guilty.

In the courtroom’s front benches, the two families on either side of the aisle — Ms. Carter’s and Mr. Roy’s — were also sobbing. Mr. Roy’s mother, Lynn, left the courtroom with a tissue in hand and a tight smile, while Ms. Carter rocked ever so slightly back and forth at the defense table, her chin in her hands.

In a brief statement, Conrad Roy Jr., Mr. Roy’s father, thanked the prosecutors and said: “This has been a very tough time for our family and we’d like to process this verdict, that we’re happy with.”

As he left the courthouse, Ms. Carter’s defense lawyer, Joseph…