Swiatek beat No.16 seed Pegula, the last American standing in singles at the Miami Open, in an hour and 48 minutes.
Caroline Wozniacki, Victoria Azarenka, and Jelena Ostapenko are the only other players to have made four or more WTA 1000 semifinals before turning 21.
Swiatek still has a chance to complete the "Sunshine Double" by winning Indian Wells and Miami in the same season.
Swiatek continued her strong form that saw her sweep the first two WTA 1000s of the season in her first match since confirming her rise to No. 1.
Swiatek clinched the top spot with a 6-2, 6-0 victory over Viktorija Golubic of Switzerland in the second round of the Miami Open.
The win meant that Swiatek had won 11 consecutive matches and climbed up the ladder to second place in the world rankings.
The Pole came back from a break down in each set, saving two set points in the first-set tiebreak, to win in 1 hour and 49 minutes.
The Polish player advanced to the semifinals against 2015 BNP Paribas Open champion Simona Halep after a 56-minute victory over Keys.
After the tournament was cancelled in 2020, Barty returned in 2021 and successfully defended her title.
Swiatek, who was defeated by the American 6-4 6-1 in 78 minutes, also advanced to the semi-finals of the tune-up event in Adelaide.