Under the stewardship of Michael Appleton, who was placed in temporary charge following Shakepeare's departure on Tuesday, the visitors picked up three points to move out of the relegation zone on Saturday.
A rejuvenated Mahrez was directly involved in Leicester's goals at the Liberty Stadium, sending in the cross that led to Federico Fernandez heading into his own net in the 25th minute for the opener.
Shinji Okazaki doubled their lead with a close-range finish from Mahrez's cushioned pass early in the second half, although Leicester's two-goal advantage didn't last for long.
5 - Shinji Okazaki has scored five goals in his last nine PL games, as many as he managed in his previous 51 in the competition. Turnaround. pic.twitter.com/NxVhUNrAyR— OptaJoe (@OptaJoe) October 21, 2017
Alfie Mawson's volleyed finish on the turn in the 56th minute gave Swansea hope, but Paul Clement's side could not find an equaliser and have now lost four of their five home league outings this season.
Appleton – whose last match in full charge of a team was Oxford United's 2-0 win over Shrewsbury Town in League One back in April – made just one change from the side Shakespeare picked for Monday's 1-1 draw with West Brom, recalling Okazaki up front.
The Japan international was at the heart of the visitors' positive start too, his header from Marc Albrighton's cross testing Lukasz Fabianski inside the opening minute.
Swansea needed their goalkeeper to spare them again when the Leicester pair reversed roles, Okazaki this time with the delivery for his team-mate to unleash a first-time drive that, fortunately for Fabianski, was aimed straight at him.
Jamie Vardy also sent in a long-range drive that needed tipping over before Swansea helped out their opponents by putting the ball beyond the Pole in the home goal.
Having done well to keep Okazaki's long ball in play on the left, Mahrez whipped over a cross that Fernandez nodded into his own net despite being under little pressure.
The Algerian winger set up Leicester's second four minutes after the restart when he broke beyond Swansea's offside trap and teed up Okazaki, who just about bundled home.
Conceding on the counter-attack was a sucker punch for Swansea, although they quickly recovered from the blow to halve the deficit.
A scuffed corner from Renato Sanches posed little threat until Jordan Ayew flicked on at the front post, allowing Mawson to swivel and find the far corner of Kasper Schmeichel's net.
Swansea tried in vain to find an equaliser, substitute Wayne Routledge the closest to scoring with a low drive that only hit the side-netting.
However, Leicester held firm through to the final whistle to secure a victory that ends a difficult week on a high.
Key Opta stats:
- Since the start of 2015-16, Swansea have scored 11 own-goals, more than twice as many as any other side.
- Shinji Okazaki has scored five goals in his last nine Premier League games, as many as he managed in his previous 51 in the competition.
- Mahrez has had a hand in five Premier League goals against Swansea (four goals, one assist); against no other side has the winger been involved in more goals in the competition (also five v West Brom).
- Jordan Ayew has been directly involved in more Premier League goals than any other current Swansea player since his debut in the competition in February 2017 (seven – two goals, five assists).