BOSTON (Reuters) - A Massachusetts man on Tuesday was sentenced to six months in federal prison for having possessed a handgun with its serial number filed off that the Boston Marathon bombers used to kill a police officer while trying to flee the city.

Merwahi Berhe, 22, pleaded guilty in March to having possessed the Ruger P95 9mm semiautomatic handgun that the ethnic Chechen brothers who killed three people and injured 264 in the April 15, 2013, bombing used three days later to shoot dead Massachusetts Institute of Technology police officer Sean Collier, as they prepared to flee the city.

Berhe was never charged with playing any role in the attack. He did not directly loan the gun to the bombers, but passed it on to another person, not named by federal prosecutors, who in turn lent it to Stephen Silva, a high school friend of the younger bomber, Dzhokhar Tsarnaev.

Tsarnaev had told Silva that he intended to use the weapon to rob people in Rhode Island.

Dzhokhar Tsarnaev and his older brother Tamerlan shot Collier dead as he sat in a patrol car, in an unsuccessful attempt to steal his service weapon, hours after the FBI released photos of the pair at the race finish line, saying they were prime suspects in the attack.

The two went on to carjack a graduate student and engaged in a gunfight with police in Watertown, Massachusetts, during which the pair hurled homemade bombs and shot at officers. The fight ended with Tamerlan, 26, dying after Dzhokhar ran over him with the stolen car while fleeing police.

Dzhokhar, now 23, was later found hiding in a dry docked boat in a suburban backyard. He was found guilty of his role in the attack in a 2015 trial and sentenced to death by lethal injection. He is currently being held at the "Supermax" federal prison in Florence, Colorado, while his attorneys appeal his sentence.

(Reporting by Scott Malone; Editing by Chris Reese)