With that, the Bombers were able to salvage the finale of the three-game series, though they still trail the Red Sox by six games in the American League Wild Card standings and the Tampa Bay Rays by 10 games in the AL East.
The Red Sox, who were struggling mightily on the road during the early and middle portions of the season, went 6-3 on this three-city road trip.
"We had a real good trip," said Red Sox manager Terry Francona. "We played good baseball. I thought we played good baseball today. We didn't get a win. I think everyone around here feels good about our ballclub. I think the players do, I do, [general manager] Theo [Epstein] does. We lost a tough game today."
Justin Masterson opened the ninth for the Sox, and the winning rally was set up by a Xavier Nady single, a stolen base by Brett Gardner, who pinch-ran for Nady, a one-out intentional walk to Hideki Matsui and a walk to Ivan Rodriguez on a 3-2 pitch.
"I just missed spots and didn't put the ball where I wanted to," said Masterson. "If I had been able to do that, it probably would have been a different situation. That's pretty much what took place."
Papelbon then replaced Masterson, but Giambi struck his 96-mph heater into center, one-hopping to Jacoby Ellsbury and ending the game.
"We just made a mistake 0-2," said Red Sox catcher Jason Varitek.
After a tough couple of days for the Yankees, Giambi relished the moment.
"I was hoping to get a chance to play a part in this ballgame," Giambi said. "The battles that we've had the last few years, things have gone on with the Red Sox. It ended like it should against the Red Sox -- coming down to the last out."
A little bit earlier, the Red Sox didn't think it would come to that. Left-hander Jon Lester walked off the mound with two outs in the seventh and a 2-0 lead. But things turned sour quickly, as Giambi greeted lefty reliever Hideki Okajima with a game-tying two-run homer over the wall in center. Just like that, Lester's 15-inning scoreless streak at Yankee Stadium was over.
"We tried to get a fastball down and in, and it was belt high and he crushed it," said Francona. "It was certainly not what we were looking for."
For Okajima, it was a setback after the lefty had been unscored on in his past four outings.
With Lester at 119 pitches, Francona felt he had little choice but to make the switch. The results just didn't pan out.
Overall, it was a good start for Lester, particularly when you consider he was coming off his worst outing of the year, an 11-0 loss to the Blue Jays.
"I felt pretty good," said Lester. "I thought I had some good stuff early on -- got into some jams and got out of some jams. Obviously, this isn't the outcome that we want, but we had a good road trip. Hopefully, we can carry this momentum back home and continue to play well."
The pitchers' duel lived up to expectations, as the game was scoreless entering the fifth. But Mike Mussina cracked -- albeit slightly -- before Lester did.
Jed Lowrie started that fifth-inning rally with a single to left. Alex Cora was then hit by a pitch, setting up Varitek for an RBI single to right. Ellsbury made it 2-0 with a fielder's-choice grounder to second.
From there, the Red Sox couldn't get anything going offensively, and they paid for it.
It certainly wasn't the first heartbreaking loss for the Red Sox at Yankee Stadium, but it very well could have been the last.
"Like I said, leading up to it, it's an exciting thing for baseball, it's an exciting thing to be a part of," Varitek said of playing at Yankee Stadium.
The record will show that Masterson -- who took the loss -- was the last pitcher of record for the Red Sox in a regular-season game played at "The House that Ruth Built."
"With all the tradition and everything that's been here, it's great to say that I played here once," said the rookie right-hander.
Other players downplayed it.
"To be honest with you, I haven't put much of an emphasis on that," said Red Sox first baseman Kevin Youkilis. "I'm trying to play a game and all that, and maybe down the road, I'll think about it. Some of us players kind of like the idea of new -- new clubhouses and new, nice fields."
The rivalry resumes at Fenway Park on Sept. 26, when the Yankees come to Fenway Park to close out the regular season for both teams.