SEATTLE -- John Danks looked destined to be a tough-luck loser on Tuesday against the Mariners.

The left-hander had allowed just one run over eight innings -- his longest outing of the season -- but watched his team come to bat in the ninth trailing against Seattle closer David Aardsma.

But some late-game heroics by his shortstop turned him into a winner on this night, and the White Sox team psyche may have taken a 180-degree turn in the process.

Alexei Ramirez ripped a three-run homer over the left-field fence with one out in the ninth inning, the first signs of offensive life the White Sox had seen all game in a 3-1 win in front of 19,385 at Safeco Field.

Ramirez's blast couldn't have come at a better time -- for Danks, or for the White Sox. They were in danger of losing their third consecutive game, as well as their fifth out of their last six, and were about to squander another chance to gain ground on Detroit in the American League Central Division race.

Then Ramirez connected, Bobby Jenks closed the door in the ninth and the Sox went back to the clubhouse happy.

"Huge game for us," manager Ozzie Guillen said. "Not because we won, but because of the way we were playing. To turn around like that against one of the guys that's been throwing the ball unbelievably well for them. ... If we win today, that could carry over into tomorrow, and then the next game. Hopefully that happens."

It looked as if Danks' stellar outing -- the first solid effort from a White sox starter in six games -- was going to go to waste. The White Sox managed virtually nothing off Mariners rookie starter Doug Fister, who threw six innings of one-hit ball in his first Major League start, and the Mariners took a 1-0 lead in the fourth inning on an RBI single by Russell Branyan.

That lead felt more insurmountable for the White Sox as the Mariners turned it over to their usually reliable bullpen. Mark Lowe relieved Miguel Batista in the seventh to work out of a two-on, two-out jam, then tossed a scoreless eighth to set the stage for Aardsma -- and his 27 saves -- to close it out.

That's when the Sox finally found their bats.

"I know these guys are out there giving it their all, and you've got to tip your hat to those guys over there," Danks said. "They've been throwing the ball well. Whenever we get on the field, we're happy to score three runs off anyone."

A.J. Pierzynski led off the ninth with a walk, then Carlos Quentin singled to move the tying run into scoring position. And with the count 2-2, Ramirez smoked his 13th home run of the season.

That they did it off Aardsma, who had given up just one home run this season, made the comeback that much more improbable -- and important. A loss could have sent the White Sox spiraling, Guillen said. Instead, they moved to two games back of Detroit atop the AL Central standings, and have a chance to take the series from the Mariners on Wednesday with Mark Buehrle on the mound against Felix Hernandez.

"I think this game could go either way," Guillen said. "If we lose this game, I think it can hurt this ballclub, because of the way we were playing early, the way we were swinging the bat. And seeing Danks throw the ball the way he was throwing the ball, we couldn't do anything."

Danks scattered seven hits and struck out eight batters in one of his best starts in a while. He notched his 10th win of the season, beat the Mariners for the first time in his young career and kept his team in the game on a night when the offense recorded 25 outs before putting a dent on the scoreboard.

"I've actually had kind of an up-and-down year as a whole, and I was kind of in a little bit of a slump, you could say," Danks said. "It wasn't pretty, and to come out here and get a win against a team that I've never beat in my career ... to come out here and pitch well in this ballpark means a lot."

It meant a lot more to win.

"It was nice to finally win a game like that," Pierzynski said. "We hadn't won a game like that in a long time, so it was nice to get it done."

The White Sox had barely made a whisper until Ramirez snapped them out of their lull. Jim Thome's infield single in the first inning was Chicago's only hit until the eighth, and the Sox didn't move a runner past second against Fister after stranding Gordon Beckham on third base in the first inning.

"That's a good-hitting club over there," Mariners manager Don Wakamatsu said. "[Fister] kept them off balance, jammed some guys. His ability to throw off-speed stuff adds a couple miles per hour to his fastball."

Chicago's luck -- and Danks' -- finally changed in the ninth.

"We needed that from him," Guillen said. "He needed that for himself, too."

They needed Ramirez just as badly.