Giants rally in 9th to beat Mets 5-4