Sabalenka was not at her best and made 37 unforced errors in the match, but the Australian Open champion bounced back midway through the second set to win 10 games in a row and take control.
Sabalenka saved a set point at 5-1 but Sherif, playing in her first WTA 1000 quarter-final after beating three seeded players, served out to take the opening set.
The Egyptian took the lead in the second set too before Sabalenka, who was a break down, finally found her groove to break four times and force a decider.
She played unbelievable tennis, she's a claycourt specialist and I'm very happy with this win," Sabalenka said.
Karatsev, ranked 121 in the world, has now beaten world number three Medvedev twice in his career with both wins coming on clay.