I think the biggest tragedies of actors in their prime leaving behind wonderful final films would be the much discussed cases of Brandon Lee, Heath Ledger, (with either the completed Dark Knight or incomplete Dr Parnusus, sp?) River Phoenix and James Dean.
Bruce Lee also passed after Enter The Dragon and of course Ollie Reed's peformance was probably a career best in Gladiator and I think Vincent Price left on a fittingly bittersweet tribute with Edward Scissorhands.
Brando did The Score which is a good film, but probably not wonderful.
Very recently Pete Postlewaite's small part in Inception, which when you look at the character he was playing is eerie, although I think the diagnosis had already been made at that point, not sure.
As for actors leaving terrible films though, er.. not sure, I saw the John Candy Bio channel thing that said his western comedy was a flop although he was loving the job until he passed away. Does Laurence Olivier count? With that godawful greenscreen film.