An easy way out is having Peter recognised and honoured when in Riga, and thus not having the same grudge against Sweden, and/or Patkul getting a pardon when fishing for it 1698, so he does not go to work to bring the anti-Swedish coalition together.
I don't think Karl XII would necessarily...