ST. PETERSBURG -- Six goose eggs by Scott Kazmir and a healthy dose of Willy Aybar put the Rays back in business on Thursday night.

Thanks to the pair's contributions, the Rays were able to take a 7-5 win over the Yankees and dodge getting swept in the finale of a three-game series with 26,080 watching at Tropicana Field.

The win came just at the right time for Tampa Bay, which had struggled out of the gate in September, losing the first two games of the season's final month after winning 21 of 28 games in August. With the victory, the Rays moved to 85-53 on the season and picked up a half-game in the standings to improve their lead in the American League East to 3 1/2 games over the idle second-place Red Sox.

"To lose three in a row here would not have been any fun at all," Rays manager Joe Maddon said. "It's the confidence, that good feeling you're able to maintain, that's the vital part of it. You don't want to get swept [heading into a road trip]."

Kazmir has always had electric stuff, but he has battled the strike zone all season, which has led to elevated pitch counts and early-inning hooks by Maddon. On Thursday night, he appeared headed toward yet another early exit when the Yankees' veteran hitters worked him for 24 pitches in the first inning. But Kazmir righted his ship with a 10-pitch second, and by the time he took the mound in the third, he had a cushy 5-0 lead.

"It always feels good when you have a lead, especially early," Kazmir said. "You feel a little more comfortable out there, you feel like you can attack the strike zone more."

The 24-year-old left-hander held the Bombers hitless through four innings before finally allowing a leadoff double to Cody Ransom in the fifth. That would be all the hits the Yankees could manage off Kazmir during his six innings.

"We've been able to get to him in the past, even when he had a lead," Yankees center fielder Johnny Damon said. "Tonight, he was definitely on. We did not hit a ball hard off him."

Kazmir did walk five, but he struck out seven en route to his 11th win of the season. The six scoreless innings lowered Kazmir's ERA to 2.99.

"Kaz was very good," Maddon said. "Overall really good command, good velocity, found a rhythm, got him out after six there, right around 100 pitches. He did a nice job."

The Yankees made it interesting in the ninth by scoring five runs off Jason Hammel, an effort fueled largely by back-to-back home runs by Derek Jeter and Alex Rodriguez. Dan Wheeler entered the game with two outs and quieted the rally with one pitch by getting Xavier Nady to fly out to end the game, earning the righty his 11th save of the season.

A night earlier, Aybar seemed to personify the Rays' frustration. But on Thursday night, that frustration turned to joy when he led an offensive surge.

The Dominican Republic native has started at third in all 23 games since everyday third baseman Evan Longoria went down with a right wrist fracture on Aug. 8. When Aybar lined into a rally-killing double play on Wednesday night, he slammed his bat against the ground in frustration, splitting the lumber into two pieces. On Thursday, he lined out in similar fashion to end a scoreless Rays first inning. This time, he gently laid down his helmet and his bat. His next opportunity came in the second inning, and he singled home two runs to put Tampa Bay up, 5-0.

"You can't live in the past; you've got to focus on the present, and that's exactly what I did tonight," Aybar said through a translator. "It was frustrating at times, but you have to keep swinging."

Aybar, who was unable to make two plays in the field on Wednesday night, rose to the occasion with his glove in the third, when he dove to his left to snare Jeter's drive, then he threw out the Yankees shortstop at first.

"You've got to defend that guy, you've got to keep him off base," said Aybar, who added a solo home run in the fourth that put the Rays up, 6-0.

Aybar was hardly the only offensive hero for the Rays. Six different players hit safely in the five-run second, when the Rays sent 10 batters to the plate. And Dioner Navarro went 4-for-5 to pace the 14-hit attack.

In addition to avoiding a sweep on Thursday night, the Rays snapped a four-game losing streak to the Yankees.

"You know it was just huge for us to get this win right now, cause it kind of felt like that last game [Wednesday] kind of hurt us a little bit," Kazmir said. "We played a little sloppy, I guess, you could say, and to come out and take care of business today, it was huge for us to go into the road trip."