From the start, Montgomery County detectives figured the killer probably knew his 12-year-old victim, Jessica Nguyen. The honor student was found stabbed to death in her family’s Gaithersburg basement more than four months ago, apparently by someone wielding a small sword. There was no sign anyone had broken in.

Now, with the first court appearance Wednesday of David R. Hang, 42, the complicated story of how the suspect knew Jessica is coming into focus. Prosecutors say it goes to a motive in the killing: Hang had entered into a sham marriage with Jessica’s mother to help her gain citizenship but had difficulty getting out it after he fell in love with someone else and married her, too, they say.

“The defendant was angry with the victim Jessica Nguyen’s family,” prosecutor Stephen Chaikin said in court Wednesday.

“That’s not true,” said Hang, speaking in court through a live video feed from the county jail.

Later in the hearing, Hang, who worked as a Ride On bus driver, broke down.

Jessica Nguyen, 12, was killed in Gaithersburg. (Courtesy of Montgomery County Schools)

“I’m a good husband,” he said through tears. “I work hard.”

Prosecutors say that in the afternoon or early evening of May 31, Hang went into the townhouse where Jessica lived with members of her extended family. He is accused of stabbing and cutting her. A sheath made to hold a small sword was left near her body.

About 7:30 p.m., an aunt asked Jessica’s teenage sister, who had fallen asleep before starting her homework, to find her. The sister looked upstairs to no avail and eventually found Jessica dead in the basement.

Detectives talked to all of the townhouse residents. They also questioned Hang, who had lived there in the past and at one point had a key, Chaikin said in court. Forensic evidence helped build their case.

Hang, who was ordered held without bond, was “included as the major contributor” of DNA found on the sheath, according to court papers, though he told detectives he had never seen it before when they showed him a photo.

Detectives also collected size-eight boot impressions at the scene and matched them to the Bates brand of boots that Ride On had formerly issued to drivers, court papers said. Hang told detectives that he wore a size eight and had been issued Bates boots, but he said he did not wear them because of discomfort.

Members of Jessica’s family, including the sister who discovered her body, sat in the front row of the courtroom Wednesday, some crying. Friends, relieved by the arrest, remember Jessica as a bright, beautiful girl.

Betty Dowdy, a substitute teacher and vice president of the Gaithersburg Middle School PTA, said Jessica was a sweet child who was quick to volunteer. “Her hand would be one of the first ones that would go up,” Dowdy said.

“She was like a little doll,” Dowdy said. “Who would do this to a 12-year-old?”

For the past five years, Hang drove a bus for Montgomery’s transit system. (He was suspended Tuesday after his arrest.) He also offered day trading services, according to a Web site he created that stated: “It’s like printing your own spendable money.”

Police said they were also looking into whether Hang offered another service: one tied to multiple marriages. “He was possibly being paid to marry all these women in an immigration-related sense,” said Officer Janelle Smith, a police spokeswoman.

Hang and Jessica’s mother, Khen Kim Vu, married in 2006. He eventually moved out of her house. On Oct. 25, Hang filed for divorce and appeared to want the proceedings to go quickly — ahead of a date proposed by a judge.

“Can it be any earlier?” he asked in court Jan. 7, according to a recording of the hearing.

His wife retained a lawyer and filed a counter-claim asserting that Hang had committed adultery and that his mistress was pregnant with his child, according to court records. Vu demanded child support even though Jessica and her sister were not Hang’s biological daughters.

At a subsequent hearing, Vu’s attorney laid out his argument: Hang had sponsored Vu on immigration issues and signed an affidavit saying he would support her and her children, according to a recording of the hearing.

Hang admitted to only part of that.

“Although he signed an affidavit of support in the immigration process, [Vu] has since received her work authorization, a two-year green card, and then a ten-year green card. She is currently eligible for naturalization,” Hang’s attorney, C. Broughton Shedlick, wrote in a Feb. 28 court filing. “There is no evidence that she is not self-sufficient or that the household fails to meet the poverty guidelines.”

Shedlick said Wednesday that Hang was frustrated that his wife hired a lawyer. But the two settled their case — with Vu agreeing to drop the child support claims and Hang agreeing to a later divorce date.

“He’s a very soft-spoken, very quiet, introverted kind of guy,” Shedlick said. “What I could see was simply a normal guy.”