I can think of two movies where the good guy/main character dies before his bad guy counterpart gets his just deserts:
To Live and Die in L.A. William Petersen, whose character barely qualifies for ‘good guy’ status, eats it before he can exact revenge on the counterfeiter (Willem Dafoe) who killed his partner.
The Departed Same thing. DiCaprio bites it before Damon does. I knew we hadn’t seen the last of Wahlberg.
I thought both movies were good, and the ‘good guy doesn’t always win’ aspect only added to it; they were good movies nonetheless.
In Sympathy for Mr. Vengeance , every main character dies. The kidnapper, the kidnapped, the single father of the kidnapped, the kidnapper’s girlfriend, and the people that left the kidnapper to die after removing his kidney.
In my favorite old war movie, Von Ryan’s Express, Frank Sinatra saves the POWs from the Nazis and is gunned down as he is running to catch the train they also liberated.
In that wonderful tribute to '60s optimism, Night of the Living Dead, everybody dies, including the semi-heroic black guy who is mistaken for a zombie right at the end.
For a more upbeat ending to the story, read the novel (which is better than the movie anyway).
I might also mention Bridge Over The River Kwai as an example of a movie where the “good guys” die, but there’s a hell of an explosion that makes up for it.
U-turn. After all the guy has been through - escaping from the Russians, dealing with the mechanic, surviving the convenience store robbery, killing Nick Nolte’s character, getting away from the sheriff, and then finally killing the woman, after being pushed off a cliff and climbing his way back up - the hose in his Mustang blows out, and he dies in the desert right back where he started.
Uhm… I’d have to ask for some elaboration on that interpretation, cause I never got that vibe from the movie. In the book, Tyler is very much dead, but nobody from Project Mayhem acknowledges it, continuing to believe that Jack is Tyler and carrying on his mission, despite any arguments he makes to the contrary (Of course, at the end of the book, IIRC, Jack is in some sort of mental institution, so he could just be crazy).
In Sin City, probably one of the few good guys who are actually all that good, Detective Hartigan, dies after killing the Yellow Bastard, the most obvious bad guy, while not having touched the Roarks, the greater evils who empowered YB, or Kevin, their other product. The Good Guys™ have gradually better fates the farther down the sliding scale of morality they happen to be located on.
ETA: Ooh, do the Matrix movies count? Neo dies in the first film before dispatching Smith the first time, and in the last movie, I think he dies some very short period of time before the Smiths are vanquished.
This being the only movie on the list that I’ve seen, I’ll comment here: Jack counts, because Cal outlived him by a couple of decades, Rose doesn’t, cause she outlived all of the villains in the movie, and most of the good guys too.