Thames hit a long home run in the eighth off Texas reliever Frank Francisco to draw New York within one run, but there was still lifting to be done as the Bombers toppled closer Neftali Perez in the ninth.
Lance Berkman opened the ninth with a walk and Brett Gardner sliced a hit to left field, with pinch-runner Curtis Granderson moving up on a wild pitch. Derek Jeter dribbled a game-tying single through the middle, and Thames followed with a run-scoring hit through the left side off Ogando.
"The guys did a tremendous job," said closer Mariano Rivera, who pitched the ninth for his 24th save. "Definitely, we chipped a little bit here, a little bit there. We had a great chance to win, a lot of opportunities. Thank God we were able to do it."
One night after standing at his locker saddled with a loss, Rivera walked a high-wire when Elvis Andrus slid headfirst into third base with a leadoff triple, representing the tying run.
Austin Kearns secured the first out with a shoe-string catch in right field, Rivera coolly got Josh Hamilton to bounce back to the mound, and Alex Rodriguez fired a Vladimir Guerrero grounder across the infield to secure New York's Major League-leading 70th win.
"I just have to focus on the guy at the plate," Rivera said. "That's the one that is going to do the damage, not the one on third base. You start figuring out how you are going to get this thing going. The rest is making your pitches."
Played in front of a sellout crowd of 48,676 that included President George W. Bush, the late theatrics completed the comeback from what had been a 6-1 deficit against Lee, though the tough left-hander lived up to expectations in an 11-strikeout performance before running out of gas late.
"It was one of the hottest games I've ever pitched," Lee said. "But it was hot for both sides. That's part of playing in Texas; you've got to figure out how to play in the heat. That's an excuse, I'm not going to make excuses. You can't change the environment, you have to figure out a way to deal with it."
Of course, the Yankees thought Lee could be installed in their rotation by now, coming close to acquiring him from the Mariners on July 3 before he was sent to Texas later that day. Now that he is headlining a Rangers club that has its eyes set upon October, proving they can beat Lee represents a confidence boost.
"It's a good win for us to battle back against a guy like that, pitching the way he was," Thames said. "He was tough tonight. I guess he got tired. It was a great game and nobody ever quit. We took pride in that and we finally got to him."
Lee was looking to improve upon victories over the Yankees in Games 1 and 5 of last year's Fall Classic with the Phillies, as well as a complete game on June 29 in the Bronx, when Lee was toiling for the Mariners.
And he seemed on his way, limiting the Yankees to two runs through the first six innings, touched by an A-Rod RBI double in the fourth and a wild pitch in the sixth inning that allowed Jeter to score after a triple.
The Yankees banged on the door with two more runs and four hits in the seventh, chasing Lee with Berkman's ground-rule double and Gardner's run-scoring single, but Darren O'Day struck out Jeter and Darren Oliver fanned Nick Swisher to kill the threat.
"Our guys just stayed at him. We all know how good he is," manager Joe Girardi said. "You look up and I think he's got nine walks on the year. You know that he doesn't beat himself. Our guys just kept pecking away and trying to put good at-bats. He started making a few mistakes, and all of a sudden, we were back in the game."
Javier Vazquez started for New York and was battered for six runs on eight hits in 4 1/3 innings, going winless for a third straight start as the right-hander continues to fight through a "dead arm" period that has affected his velocity.
"It's just frustrating for me," Vazquez said. "All my career, I'm used to pitching 91 to 94 [mph]. Just seeing 87 and 88 is kind of frustrating. I guess I have to pitch with that, if that's what I have. ... I've got a lot of innings in my arm. Maybe it's catching up to me."
Michael Young slugged his 17th home run off Vazquez in the first inning to put the Rangers on the board, and Texas added in the fourth on Mitch Moreland's two-run single, which caromed off Berkman's glove at first base and shot into right field, allowing Hamilton and David Murphy to score.
In the fifth, Hamilton rocketed a run-scoring double and Murphy came through with a two-run single that ended Vazquez's evening.
That left a bleak picture, but New York got 1 2/3 innings of scoreless relief from Sergio Mitre and two blank frames from local product Kerry Wood to hold the fort until the bats could wake up against Lee and the Rangers' bullpen.
"That shows you what kind of team we have," Rivera said. "I never give up on these guys. We are capable to do this, and tonight we showed it."