BOSTON — A man who lent the convicted Boston Marathon bomber the gun used to kill a police officer three days after the deadly 2013 attack was set to be released from prison after a judge sentenced him to time served Tuesday for drug and firearms charges.

U.S. District Judge Mark Wolf sentenced Stephen Silva, who was arrested in July 2014, to time served plus three years’ supervised release for the charges that he pleaded guilty to last year.

Silva was not accused of playing any role in the April 15, 2013, bombing at the Boston Marathon finish line, which killed three people and injured 264, but admitted having possessed a handgun with its serial number filed off.

He testified in March that he lent that gun, a Ruger P95, to Dzhokhar Tsarnaev, who told him he wanted it to rob college students in Rhode Island.

According to the U.S. Attorney’s Office, investigators traced the murder weapon to a convicted Portland, Maine, crack dealer named Biniam “Icy” Tegal. The weapon then passed to a pal of Silva’s, then to Silva, and finally to Tsarnaev.

Tsarnaev was found guilty in April of carrying out the bombing attack along with his older brother, as well as shooting dead Massachusetts Institute of Technology police Officer Sean Collier three days later.

Tsarnaev’s older brother, Tamerlan, 26, died after a gunfight with police later that night and it was never established which of the pair pulled the trigger to kill Collier.

“I would like to apologize for the crimes I committed. For the record, I had no idea that the firearm I lent to Mr. Tsarnaev would be used in the way it was,” Silva told the judge before his sentence was read. “I was young, dumb and thought I could outsmart everyone.”

Prosecutors had sought an 18-month sentence, citing the defendant’s cooperation in the bombing investigation. They noted that he testified that Tsarnaev, whom he had been friends with since childhood, had actively sought the gun from him, evidence that helped undercut Tsarnaev’s lawyers assertion that he had been a secondary player in a plot planned by his older brother.

“You were at a crossroads and you certainly went in the wrong way,” Wolf said. “You didn’t just go in the wrong way, you got a gun, gave it to your friend and as a result of that, now a police officer is dead.”

Silva is the last of five people associated with Dzhokhar Tsarnaev to face criminal charges related to the bombing. Three of his college friends and a cabdriver who had been friends with both brothers were in June sentenced to three to six years in prison for lying to investigators.

Tsarnaev was sentenced to death by lethal injection and plans to appeal.