As long as the team never gives up the lead, the final score doesn’t matter. If Pitcher A left with the lead and the other team never ties it up or goes ahead, Pitcher A gets the win.
This is the key bit – what matters is if the team ever relinquishes the lead, not who the pitcher of record was when the team scores the run that proves to be the eventual margin of victory.