By Agence France-Presse
The deal struck by 23-year-old Karim Baratov, who immigrated to Canada from Kazakhstan, also resulted in a fine that "encompasses all his remaining assets," the US Justice Department said in a statement.
Baratov has been in American custody since being extradited from Canada last year on a US warrant for hacking, commercial espionage and related crimes.
US authorities allege Russian intelligence agents hired Baratov and another hacker to carry out attacks on Yahoo from 2014 to 2016.
The data breach compromised 500 million Yahoo accounts and is one of the largest cyberattacks in history.
"The sentence imposed reflects the seriousness of hacking for hire," said prosecutor Alex Tse.
"Hackers such as Baratov ply their trade without regard for the criminal objectives of the people who hire and pay them."
Targets included Russian and US government officials, cyber security, diplomatic and military personnel, journalists, companies and financial firms.
"It's difficult to overstate the unprecedented nature of this conspiracy, in which members of a foreign intelligence service directed and empowered criminal hackers to conduct a massive cyber-attack against 500 million victim user accounts," said John Bennett, FBI special agent in charge for the San Francisco field office.