The hosts sealed the result when Edwill van der Merwe intercepted a Leinster pass and raced away to score in the 78th minute, although they allowed the visitors to have the final say via a late try from Andrew Osborne to earn a late bonus point.
The Sharks had earlier taken control through second-half tries from captain Andre Esterhuizen and Van der Merwe, following first-half scores from Manu Tshituka and Litelihle Bester. Cameo performances from returning Springbok stars Eben Etzebeth and Ox Nche also proved decisive in the second half.
Leinster started strongly and were rewarded when Robbie Henshaw finished off a period of sustained pressure in the 17th minute. Caspar Gabriel converted to give the visitors a 7-0 lead.
The Sharks responded through their dominant scrum, with Tshituka powering over in the 26th minute. Vusi Moyo converted to level the scores before Bester finished in the corner just before half-time, giving the hosts a 14-7 lead after another successful conversion from Moyo.
Thomas Clarkson was sent to the sin bin for repeatedly collapsing the scrum in the 38th minute, but Leinster came out firing after the break and spent much of the opening stages in the Sharks' 22.
Their pressure eventually paid off when Clarkson crossed in the 49th minute, although Gabriel's conversion attempt struck the upright.
Leinster moved ahead for the first time when Prendergast kicked a penalty in the 66th minute, making it 15-14.
However, the Sharks responded with a superb team try three minutes later, with Eben Etzebeth instrumental in the build-up before offloading to Esterhuizen, who powered over. Moyo converted to restore the hosts' lead.
Van der Merwe then produced the decisive moment in the closing stages, intercepting a Leinster pass and racing clear to score, before Osborne's late try proved insufficient to deny the Sharks a bonus-point victory.