A former graduate student at M.I.T. has pleaded guilty to killing a Yale graduate student in January 2021 in a gruesome shooting that shocked people on both university campuses.

The defendant, Qinxuan Pan, 32, narrowly escaped arrest just minutes after the murder. He spent the next three months hiding from law enforcement, and the following two years maintaining his innocence. That changed on Thursday, when Mr. Pan pleaded guilty, possibly bringing an end to a case that had caused some Connecticut residents to question the competence of local police.

Mr. Pan faces a single charge of murder, according to a statement by John P. Doyle Jr., the state’s attorney in New Haven. As part of his plea agreement, Mr. Pan could face 35 years in prison. He is scheduled to be sentenced on April 25.

The prosecutor’s office made no mention of Mr. Pan’s possible motives for the attack. In a 96-page warrant filed in state court in February 2021, a New Haven police detective described Mr. Pan’s actions as follows:

In 2019, when he was a doctoral student in M.I.T. ’s department of electrical engineering and computer science, Mr. Pan met Zion Perry, an undergraduate student at M.I.T., and they became friends. The two remained in contact through Facebook, where Ms. Perry posted an announcement celebrating her engagement on Jan. 30, 2021, to Kevin Jiang, a 26-year-old graduate student in environmental science at Yale.

A week later, on Feb. 6, 2021, Mr. Pan allegedly stole a dark blue S.U.V. from a dealership in Massachusetts, according to a criminal complaint filed by the police department in Mansfield, outside Boston. He drove to Ms. Perry’s neighborhood in New Haven, near the campus of Yale, where she was a doctoral student in biochemistry and biophysics.

Mr. Jiang and Ms. Perry had spent much of the day together. They went ice-fishing and cooked dinner at her apartment. He left a few minutes after 8 p.m., and climbed into his Toyota Prius. He had driven only a few blocks before Mr. Pan rammed him with the stolen S.U.V., according to the warrant. Mr. Jiang got out of his car, and Mr. Pan fired eight bullets at him, including multiple shots to his face.