Tony Stewart holds off Denny Hamlin to win Toyota/Save Mart 350

Tony Stewart won the drama-filled Toyota/Save Mart 350 at Sonoma Raceway on Sunday, increasing his chances of making the 2016 Chase for the Sprint Cup despite missing the first eight races of the season.

"It's special, trust me," Stewart said after ending an 84-race winless streak with his 49th career Cup win.

The closing laps were intense as Stewart worked hard to hold off the rest of the field in his No. 14 Stewart-Haas Racing Chevrolet, with Martin Truex Jr. and Denny Hamlin stalking him.

But Truex and Hamlin kept battling each other hard, which helped Stewart increase his lead. With eight laps to go, Stewart's lead was close to two seconds over Hamlin, who finally made the pass for second on Truex one lap earlier.

By five to go, Stewart's lead was down to less than a second. 

Hamlin finally caught and passed him going into Turn 7 on the final lap, and looked as if he was going to go on to score the win. But Hamlin came into the final hairpin turn too hot in his No. 11 Joe Gibbs Racing Toyota, opening the door for Stewart to pass him back for the lead and the win.

Hamlin hit the wall as he tried desperately to pass Stewart back once again heading to the checkered flag, but was fortunate the be able to hold on for second. Joey Logano finished third, with Carl Edwards and Truex rounding out the top five.

Stewart said he tried to drive more carefully down the stretch, minimizing his mistakes after he "drove like an A-hole" earlier in the race while battling Brad Keselowski and former teammate Ryan Newman.

"I drove like an idiot because I told them on the radio, 'I'm driving like an A‑hole out here,' and I was. I was overdriving my car," Stewart said. "I was trying to do everything I could to get as much position early in the run as I could so I could try to run my pace and try to do the things to help save my tires, but I couldn't keep the pace doing it, and I wasn't going to leave anything on the table."

In the end, he didn't -- outdueling Hamlin in a memorable finish in what is Stewart's final season. He is retiring at the end of the year.

“Tony was doing a good job maintaining his tires, a good job of running consistent laps there (on the final lap)," Hamlin said. "Really he gave me an opportunity to get close. On the second-to-last lap he wheel-hopped into (Turn) 7, allowed us to get close and I just did a poor job of getting through (Turn) 11 on the final lap.

"I was expecting to really drive in deep and I really thought that was going to happen and he did, but I also left the bottom open and that was a bad mistake on my part. But it was still a great race."

After missing eight races at the beginning of the season while recovering from an off-season back injury, Stewart needed to win a race and finish in the top 30 in points after the first 26 regular-season races to qualify for a spot in the Chase for the Sprint Cup.

Sunday's race was the 16th of the regular season.

The 45-year-old Stewart took the lead on fuel strategy during a caution with 24 laps to go, and had to hold on after another yellow flag stalled the race. The final restart came with 14 laps remaining -- the same number as Stewart's race car -- and he held off a trio of Toyota drivers for his third career victory at Sonoma, and eighth on a road course overall.

Stewart now sits 32nd in the points standings, only nine points behind Brian Scott in 30th.

"This place has been nice to me in my career," Stewart said. "If I don't win another one, it's cool to win the last one here."

The Associated Press contributed to this report.