Padres rally for 4 in 9th, beat Dodgers 4-2 to avoid sweep