SAN FRANCISCO—A 23-year-old man who hacked into Gmail accounts on behalf of Russian intelligence was sentenced to five years in prison Tuesday, less than the government sought in a case trumpeted as a warning to cybercriminals and foreign intelligence services alike.

Karim Baratov, a Canadian citizen born in Kazakhstan, pleaded guilty to federal conspiracy and identity theft charges last November in connection with a black market no-questions-asked hacking service he operated from 2010 until his arrest in March 2017. Baratov charged customers about $100 to obtain another person’s webmail password, using phishing attacks that tricked users into entering their passwords into a fake password reset page. He cracked more than 11,000 accounts in Russia and the US before he was caught.

One of Baratov’s clients was an officer with Russia’s Federal Security Service, or FSB, who used an alias to commission hacks on 80 targets in all, including people in other Russian agencies, and government officials in neighboring Eastern European nations. Prosecutors had sought a sentence of seven years, 10 months in prison, in part to make other hackers think twice about offering their skills—knowingly or unknowingly—to hostile intelligence agencies.

“It is hard to catch these people,” Assistant U.S. Attorney Jeffrey Shih said in court. “And in terms of the state-sponsored connection, it really is a deterance concern.”

Only eight of the FSB-related hack attempts were successful, and the government and Baratov’s defense team agree that the hacker did not know that the commissions were coming from the Russian government.

U.S. District Judge Vince Chhabria had openly struggled to find the right sentence for Baratov, noting that he’s a relatively young defendant with no prior criminal history and strong family connections. In April, the judge unexpectedly postponed sentencing to give both sides more time to make their respective arguments.

Much of the discussion focused on weighing the seriousness of Baratov’s crimes compared to other hacking cases. Baratov’s lawyers argued for a 45 month sentence, arguing that his hacking was less serious than the large-scale thefts of credit card numbers that have drawn prison terms as high as 25 years in the United States. Prosecutors countered that Baratov was actually worse, because he targeted individuals on behalf of anonymous clients without regard for the consequences.

In the end, Chhabria sided with the government on that question, noting at Tuesday’s sentencing that Baratov believed most of his customers were jealous lovers checking on a partner. Jealous lovers, Chhabria said, have been known to “beat a former partner to a pulp.”

“In the universe of hacking type crimes, in some ways this is the worst of both worlds,” Chhabria noted. “The most logical inference by far is that this information that was provided to people was likely to be used for quite nefarious purposes.”

Baratov, standing beside his lawyers in county jail uniform, briefly addressed the judge to apologize to his victims. “The last 14 months have been a very humbling and eye opening experience,” he said. “There’s no excuse for my actions.… All I can do is promise to be a better man, obey the law and ask for a second chance.”

In addition to the prison term, Baratov was fined $250,000.

Dmitry Dokuchaev, the former FSB officer who allegedly hired Baratov, is charged as a coconspirator in the case, though he’s unlikely to wind up in a San Francisco courtroom. Dokuchaev was arrested by his own agency in December 2016 and charged with treason, under circumstances that remain shrouded in mystery.

Another FSB officer, Igor Sushchin, is also charged in the same indictment for allegedly overseeing the email hacking, as is a long-notorious Russian hacker named Alexsey Belan who was already wanted in two states for conventional cybercrime. The three Russian nationals are accused of conspiring to commit a massive 2014 data breach at Yahoo that compromised account information on 500 million users. They allegedly turned to Baratov to fill the gap when they encountered an FSB target that used Gmail, or another provider, instead of Yahoo where they had complete access.