Pirates knock off D-backs 5-4