The 26-year-old Lewis started in 16 games with the Houston Texans last season. He had 84 tackles, three forced fumbles and two interceptions.
Lewis is expected to arrive in Baltimore next week to take a physical.
The deal, announced Saturday, comes one day after the Ravens lost free agent Darian Stewart to the Denver Broncos.
Lewis played his first four seasons with Kansas City after being selected in the fifth round of the 2010 NFL draft. He has nine career interceptions, two of which he returned for touchdowns.