Right-hander Jake Faria is headed back to Milwaukee in the deal.
Aguilar, an All-Star in 2018, fills the Rays' search for a right-handed bat. He is hitting .225 with eight home runs and 34 RBIs this season. His batting average and OPS (.694) were both his worst in three seasons in Milwaukee, but his numbers were up to .298 and .920 in July.
The 29-year-old is arbitration-eligible for three more seasons.
He had a career year last season with a .274 average, 35 homers and 108 RBIs.
Faria, 26, has thrown 10 innings this season and has a 2.70 ERA. He has appeared in 40 MLB games -- with 26 starts -- over three seasons and has a 4.18 ERA and 9-8 record.
The Rays stayed busy later Wednesday, trading left-handed reliever Adam Kolarek to the Los Angeles Dodgers for minor league outfielder Niko Hulsizer. Kolarek has a 3.95 ERA in 54 appearances in 2019, with 36 strikeouts in 43 1/3 innings. Tampa Bay also dealt minor league outfielder Joe McCarthy to the San Francisco Giants for lefty pitching prospect Jacob Lopez, sources tell ESPN.
The Brewers entered Wednesday 1½ games out of first place in the NL Central and one game out of a wild-card spot. The Rays are 7½ games out of first in the AL East and a half-game out of a wild-card spot.