The world number two took the first set 6-4.
Serbia's Ivanovic pulled out a 2-0 lead in the second set but Sharapova dragged the score back to 3-3 and then dominated to deny Ivanovic another game.
World number one Williams and Sharapova have met on 14 occasions with Williams winning 12 of them.
Sharapova said afterwards: "You know first of all it's great to be in this final. It's the first time I have been in the final of this tournament which is a great reward but I do have a tough match ahead of me, and yeah, I hope I can play and maintain the same level that I have been having in this tournament."
Results from the Madrid Open Women's Singles Semifinal matches on Saturday