Ostapenko looked to be cruising after winning the opener, but Kanepi levelled in the second despite the Estonian watching five set points come and go.
Kanepi then romped to victory with a stunning final set to defeat Ostapenko 4-6 6-4 6-0 and keep her hopes of winning her home tournament alive.
In second-round action, Beatriz Haddad Maia is through to the quarter-finals after a 6-1 7-5 success over Linda Noskova.
After Haddad Maia cruised to a one-set lead, the second was a much tighter affair before the Brazilian's class showed as she broke Noskova and then held serve to earn a straight-sets win.
Second seed Belinda Bencic also secured her place in the final eight with a 6-4 6-7 (2-7) 6-3 triumph over Katie Boulter.
At the Parma Ladies Open, top seed Maria Sakkari came from behind to beat Arantxa Rus and seal her quarter-final spot.
Rus saved five out of five break points as she won the opening set 6-3 to give her hope of an upset.
Those hopes were soon dashed though as world number seven Sakkari broke twice to take the second set 6-2, before clinching the match in the third to tee up a clash with Maryna Zanevska.
World number 33 Irina-Camelia Begu made it 12 consecutive wins on clay by overcoming Matilde Paoletti in straight sets and will face fellow Romanian Ana Bogdan in the next round after she beat Anna Karolina Schmiedlova 6-2 3-6 6-3.
Fourth seed Sloane Stephens saw her tournament come to an end after she was defeated by Danka Kovinic.