A former roommate of accused Boston Marathon bomber Dzhokhar Tsarnaev pleaded guilty in federal court today to charges that he hindered an investigation into the deadly 2013 bombings and could spend up to seven years behind bars if the Judge Douglas Woodlock approves it.

As part of the plea, Dias Kadyrbayev would be incarcerated for no more than seven years and agreed to a judicial order of deportation, which means he gave up his right to a deportation hearing. He said he understood his rights to go to trial but agreed with the plea deal reached between U.S. Attorneys and his counsel.

Kadyrbayev, 20, was scheduled to go to trial next month on obstruction of justice and conspiracy charges, but his lawyer Robert Stahl filed a change of plea notice in advance of today’s hearing.

The judge explained the elements of both charges, and Kadyrbayev said he understood he was admitting to everything, including hiding a backpack and laptop that were key aspects of the obstruction charge.

Kadyrbayev appeared in a blue polo shirt and jeans with his hands cuffed behind him. He laughed with defense attorney Robert Stahl prior to the hearing, and spoke in broken English to Judge Douglas Woodlock when answering questions about the plea.

“You understand that you’re pleading guilty to two charges … those are serious federal charges,” Woodlock said to Kadyrbayev as he explained the range of possible penalties.

Kadyrbayev said he understood the ramifications of his decision and admitted to a series of facts, including that he saw the photographs of Tsarnaev and his now-deceased brother, Tamerlan Tsarnaev, after the bombing.

Kadyrbayev admitted that he sent a text to Dzhokhar Tsarnaev after he saw the photos and later showed them to a mutual friend, Azamat Tazhayakov.

He admitted that they then went, with Robel Phillipos, to Dzhokhar Tsarnaev’s University of Massachusetts Dartmouth dorm room, and then agreed to take the backpack — filled with fireworks — and his laptop, which were “altered” when they were found, prosecutors said.

“Is that true? Did that happen?” asked Woodlock.

“Yes,” Kadyrbayev said.

Woodlock said he would not decide today whether or not to accept the plea.

Kadyrbayev will be sentenced on Nov. 18.

Tazhayakov was found guilty of obstruction and conspiracy charges last month. He faces up to 25 years in federal prison when he’s sentenced Oct. 16.

Phillipos is charged with lying to investigators, while Quincy cabbie Khairullozhon Matanov has been charged with destroying evidence.

Tamerlan Tsarnaev was killed during a police shoot out in Watertown several days after the attack. Dzhokhar Tsarnaev has pleaded not guilty to 30 federal charges and is slated to go on trial Nov. 3. He could face the death penalty if convicted.