Maria Sharapova rallied from a set and a break down to stun Ana Ivanovic and win the Porsche Tennis Grand Prix for a third year in a row on Sunday.