The one-year deal announced Tuesday is worth $3.25 million.
The 32-year-old Hernandez has pitched seven years in the majors, all with Cleveland. He was 0-3 with a 7.53 ERA last season.
Hernandez was arrested last winter in the Dominican Republic on false identity charges. They were dropped after he completed a work program. Major League Baseball later suspended him for three weeks. Hernandez sprained his right ankle in August and missed the rest of the year.
Hernandez is 53-69 with a 4.64 ERA in the majors. He was 19-8 with a 3.06 ERA in 2007 when Cleveland last made the playoffs.
Hernandez can earn performance bonuses with Tampa Bay as both a starter and reliever.
In other developments Tuesday, former Rays pitcher Matt Bush was sentenced to four years and three months in prison for a drunken-driving hit-and-run crash in Florida.
As part of a deal, the 27-year-old pleaded no contest Tuesday to driving under the influence with serious bodily injury. Six other counts in the March crash were dropped. Because it's his third DUI, Bush will also lose his license for 10 years. He already has spent nine months in jail.
Bush's attorney, Russell Kirshy, called the deal fair.
Information from The Associated Press contributed to this report.