BOSTON — A man who had dinner with the Boston Marathon bombers hours after the 2013 attack was sentenced Thursday to 2½ years in prison for misleading investigators by failing to disclose his contact with the brothers in the days after the bombings and deleting files from his computer.

Khairullozhon Matanov, 24, was a friend of Tamerlan Tsarnaev and an acquaintance of Dzhokhar Tsarnaev. He pleaded guilty in March to misleading the FBI.

Matanov saw photographs released by the FBI three days after the attack, but did not immediately call authorities. He went to police the next morning and gave them the Tsarnaevs' names, address and phone numbers, but by then the brothers had killed an MIT police officer and engaged in a wild gun battle with police in Watertown. Tamerlan was killed, while Dzhokhar escaped in a stolen car and was found later that day hiding in a boat stored in a backyard.

Judge William Young imposed the 2½-year sentence called for in a plea agreement Matanov reached with prosecutors, but harshly reprimanded him for deceiving the FBI and diverting the agency's resources at a time when they were in the throes of an active terrorism investigation.

When he was interviewed by the FBI, he did not tell them that he had called Tamerlan Tsarnaev less than an hour after the bombings and invited him to dinner that night or about contacts he had with him in the following days.

"All we asked you was to give us a hand. All we wanted was for you to help us out, and you didn't do that," Young said.

Young said everyone agrees that Matanov, a native of Kyrgyzstan, did not know about the bombings ahead of time or participate in the attack.

The judge launched into a patriotic speech about the "common sense of decency" Americans have, citing the many marathon spectators who ran toward the bombing sites to help the injured, the firefighters who ran into the World Trade Center towers in New York City on Sept. 11, 2001, and the teachers in Newtown, Connecticut, who did not flee the school during a 2012 mass shooting, but instead stayed to try to protect the students. Twenty children and six school staff members were killed.

"It's been well said that duty is the noblest word in the English language ... You failed in that duty," Young said.

Matanov apologized for lying to the FBI.

"It was wrong, and I do not support, or I'm not a sympathizer of, any terrorist organization," he said.

Matanov will receive credit for the 13 months he has already spent in custody since his arrest in May 2014.

Susan Borts, a woman who corresponded with Matanov and visited him in prison, traveled from her home in Portland, Oregon, to support him during his sentencing hearing.

"My personal opinion is the charges were excessive," she said after the hearing. "It's a shame. He loves this country and wants to stay. He was one year away from naturalization."

Three people were killed and more than 260 people were injured when the Tsarnaev brothers planted two bombs near the finish line of the marathon April 15, 2013. Last month, a federal jury voted to give Tsarnaev the death penalty. His formal sentencing is scheduled for June 24.