The deal is for $2 million, sources told ESPN's Jeff Passan.
Hampson started at six positions last season for Miami and batted a career-best .276 with three homers, 23 RBIs and a .729 OPS in 98 games. He was eligible for arbitration this winter but the Marlins chose not to tender him a contract, making him a free agent.
The 29-year-old Hampson started 26 games at shortstop last season, 13 in center field, eight in right field, six at second base, four at third base and two in left field, helping Miami reach the playoffs.
Before signing with the Marlins, Hampson spent his first five seasons with the Colorado Rockies. He is a .241 career hitter with 29 home runs and a .676 OPS in 517 games over six major league seasons. He has 57 stolen bases in 70 attempts.
Hampson can earn $200,000 in performance bonuses with Kansas City. He joins a struggling Royals team that finished last in the AL Central this year at 56-106.
Hampson was selected by Colorado in the third round of the 2016 amateur draft out of Long Beach State.
The Associated Press contributed to this story.