Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

A former U.S. Customs and Border Protection watch commander was sentenced Monday to just over 2½ years in prison for operating an illegal gun-selling business and other crimes, including failing to disclose contacts in China while receiving security-level clearance, federal prosecutors in California said.

Wei Xu, 58, of Santa Fe Springs, California, pleaded guilty in July to dealing in firearms, possessing unregistered firearms, making materially false statements to a federal agency and tax evasion.

Prosecutors said Xu used his status as a law enforcement officer to buy and sell off-roster handguns, or those not approved for sale to the general public. He also admitted to having sold 99 guns over 20 years without a required federal license.

"Mr. Xu betrayed his oath to uphold the laws of the United States solely to put more money in his pocket," Nick Hanna, the U.S. attorney for the Central District of California, said in a statement.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

Hanna said that Xu endangered the public by selling off-roster firearms and that he lied to cover it up.

Xu's attorney, Mark J. Werksman, said that the sentence was fair and that the judge reduced it by a year out of respect for Xu's service with Customs and Border Protection. Xu, who began working for the agency in 2004, is on administrative leave, but Werksman said he expects Xu to be fired.

Xu has been in federal custody since February and will get credit for time served, Werksman said.

Download the NBC News app for breaking news

The FBI said in a criminal complaint that Xu had two accounts with a website described as an online marketplace for guns and that he used them to arrange in-person sales to an undercover agent.

During one sale in July 2018, Xu showed up in a black 2016 Maserati Ghibli, and when the undercover agent commented on the car, Xu said, "I'm like you, playboy," according to the affidavit in the criminal complaint. He then sold the undercover agent a rifle.

When Xu was arrested, agents found more than 250 firearms, including 41 fully automatic weapons that were never registered with the federal Bureau of Alcohol, Tobacco, Firearms and Explosives, the U.S. attorney's office said.

The tax evasion charges stem from allegations that Xu established a "sham company" to claim fake losses to avoid paying income tax, prosecutors said. The court ordered him to pay $128,407 in restitution to the IRS.

Prosecutors also said Xu was an accounts manager for a China-based auto parts import company and concealed that information on Office of Personnel Management questionnaires to get security clearances.