ALEXANDRIA, Va. — A second Navy petty officer, suspected of plotting a terror attack and possibly plotting to help the Islamic State group, has been sentenced to more than 13 years in prison for possessing 50 pipe bombs, chemical weapons and thousands of rounds of ammunition.

The sentence was the maximum allowed under the plea agreement Vincent Russell signed in May with prosecutors, Alexandria U.S. Attorney Tom Cullen said Wednesday.

Russell, 30, of Hampton, confessed last year that he harbored concerns that his service with the Navy could harm his ability to travel to and remain in the U.S. Under his plea agreement, Russell agreed to testify against one of his co-defendants and turn over the name of the man’s father.

Russell’s trial had been scheduled to begin last month. He pleaded guilty to eight felony charges, which are more serious than the charges he faced. The charges cover crimes Russell is accused of committing in three counties in central Virginia from January 2015 through his arrest in July 2015. Prosecutors say he kept more than 50 pipe bombs in his residence, stored hundreds of pounds of inert explosives, including similar devices, guns and ammunition, and a homemade bomb that Russell disguised as a Cheerios box to detonate a homemade bomb.

Prosecutors say Russell had received remote detonation devices before his arrest from his co-defendant.

In his sentencing speech before U.S. District Judge Henry Hudson, Russell asked Hudson to reduce his sentence from the maximum penalty of 20 years to between five and 10 years. He told Hudson that he believed he was guilty of the wrong charges, but did not say why.

The judge disagreed, calling the other charges especially serious. He pointed out that Russell, who was in touch with a government informant who was an FBI agent, likely communicated directly with the FBI when he was making decisions about what to do with the bombs. Hudson also emphasized that Russell was free to go to Somalia and join a terrorist group because the government never actively pursued his case or arrested him.

Russell, who has no previous criminal record, got in trouble with the law several times while serving in the Navy. He faced at least one court-martial over abuse of drugs and received a bad conduct discharge in 2014. He has been in custody since his arrest in July 2015.

According to an FBI affidavit filed in support of the charges, Russell admitted to his girlfriend that he was contemplating a mass casualty attack on the streets of Norfolk when he had the pipe bombs, other weapons and explosives in his home.

At the time of Russell’s arrest, the FBI was looking into whether Russell was planning a terror attack on trains in Norfolk and elsewhere on the East Coast. The FBI’s informant also recorded Russell telling his girlfriend that he planned to target military installations in Norfolk and Virginia Beach.

Prosecutors say Russell likely made plans to leave Norfolk for Somalia to join the Islamic State group after his arrest in July 2015. In September 2015, Russell acknowledged in the plea agreement with prosecutors that he had wanted to travel to Somalia, and agreed to wear a wire in a deal to build a criminal case against co-defendant Abdirizak Warsame.

The court case against Warsame continues. At least two people have been sentenced in the case so far: Warsame’s father, Mahmoud, who faces a 15-year sentence in March, and his nephew, Tesfaye Muhammad Ali, who was sentenced to 24 years in prison on May 16. Ali was charged with lying to the FBI about his conversations with Russell.