Pirates rally for 5-4 victory over sloppy Mets