The deal includes a player option on the fifth year, league sources said.
Middleton has developed into the co-star to MVP Giannis Antetokounmpo on the Bucks championship contender and his commitment on Sunday re-establishes Milwaukee as an Eastern Conference favorite.
Middleton declined his $13 million player option to become an unrestricted free agent.
He was the Bucks’ top priority in a free agent class that includes Malcolm Brogdon and Brook Lopez. Lopez plans to re-sign in Milwaukee on a four-year, $52 million contract, sources said earlier Sunday.
Middleton, 27, emerged as an All-Star for the team that had the best record in the NBA and reached the Eastern Conference Finals. Middleton averaged 18.3 points, six rebounds and four assists last season. He’s a career 39 percent three-point shooter, a self-made player who emerged from a second-round pick to the Detroit Pistons
NBA free-agent contracts can’t be officially signed until July 6.