Lester (5-4) went seven innings, retiring 13 in a row after Realmuto's seventh homer of the year. Cubs starters have an ERA of 2.52 over the past 11 games.
Wade Davis completed the four-hitter with a 1-2-3 ninth for his 15th save.
Javier Baez had an RBI single in the fourth, and his two-run double off Nick Wittgren (1-1) in the sixth put the Cubs ahead to stay. Jon Jay, a one-day sub for Anthony Rizzo in the leadoff spot, had two hits and scored a run. Addison Russell had two hits and scored twice.
Lester beat Miami for the first time in five career starts.