In exchange for Lackey, the Red Sox will receive pitcher Joe Kelly and outfielder Allen Craig.
The Red Sox also sent minor-league pitcher Corey Littrell to the Cardinals.
Lackey, 35, has posted a 3.60 ERA with 116 strikeouts and 32 walks over 137 1/3 innings this season.
The Cardinals opened Thursday at 56-50, one game back in the Wild Card race and in third place in the National League Central.
- Chris Johnson