"It's hard to believe that we're sitting here and that we lost another game," said Pettitte, who retired the first 14 batters he faced and carried a no-hitter into the sixth inning. "This was a big loss, there's no doubt about it. We've got to try to pull off a miracle here."
The loss leaves the Yankees four games back of the second American League Wild Card spot with just six games remaining on their schedule, as Cleveland and Tampa Bay both won their games on Sunday.
"We're still alive, obviously, but this one really hurts," Yankees manager Joe Girardi said. "It's tough."
The day represented an emotional swing for the Yankees, who lauded Rivera's illustrious career in a star-studded, 50-minute pregame ceremony that included the appearances of many of Rivera's former teammates, gifts and the unveiling of his retired number.
"The finish wasn't what I was looking for, but it was a great day," Rivera said. "I didn't know what to feel, but when I got there -- especially at the monument, where they had the number retired already -- it was emotional."
The delay seemed to have no effect on Pettitte, who said he had to dial back his adrenaline and came out pitching splendidly, having warmed up to the soundtrack of Metallica playing a live version of "Enter Sandman" just a few feet away.
Pettitte did not allow a baserunner until Pablo Sandoval's fifth-inning walk, and no hits until Ehire Adrianza hit his first Major League homer in the sixth. Pettitte started the eighth inning, but Sandoval chased the 41-year-old left-hander with a double to left field, just the second hit Pettitte permitted.
Slamming his right thigh with his glove, Pettitte acknowledged Girardi's trudge from the dugout, handing over the ball with disappointment. He is scheduled to pitch once more before season's end, but barring a postseason appearance, Pettitte's work wearing home pinstripes is complete.
"I think that he did the right thing, announcing his retirement and pitching in front of his fans," Rivera said. "That's the right way to do it."
Pettitte doffed his cap and received a hug from captain Derek Jeter at the top of the dugout steps. He was similarly embraced by many teammates before being called back for a curtain call; one that drew applause even from the Giants on the third-base side.
"It was a great moment for me and I really enjoyed it," Pettitte said. "I was glad I got the opportunity to do that, and the fans were awesome, just like they've always been to me."
David Robertson relieved Pettitte and recorded an out, but Tony Abreu -- whom Girardi said had logged just one hit on a curveball all season -- banged a hook into right field for a double, scoring pinch-runner Nick Noonan with the go-ahead run.
"I feel like I let everybody down," Robertson said. "I let Andy down."
The bullpen doors swung open for Rivera, a non-save situation for the all-time saves leader. Rivera told Girardi that he would go as long as necessary to pick up the win, and indeed, Girardi said he would have pitched the 10th inning had there been one.
After being held to Mark Reynolds' third-inning solo homer over 6 1/3 innings by San Francisco starter Yusmeiro Petit, it looked like the Yankees would be able to salvage the storyline in the late innings against the bullpen.
"I really thought that we'd have the magic to pull this one off," Pettitte said.
Two seventh-inning singles and a passed ball moved Eduardo Nunez and Brendan Ryan into scoring position, but lefty Javier Lopez struck out pinch-hitter Vernon Wells and Ichiro Suzuki to wriggle free.
The Yankees banged on the door louder in the eighth. Alex Rodriguez opened the frame with a single and Robinson Cano scorched a double down the right-field line, putting runners at second and third base with none out.
But the Yankees were again turned aside. Pinch-runner Zoilo Almonte was erased at the plate on a fielder's choice, opting to charge home on what Girardi called "a bad read" after Noonan made a nice play on an Alfonso Soriano grounder.
"Sometimes we make mistakes, and that's the way it is," Yankees third-base coach Rob Thomson said. "He was being aggressive, he saw something and he reacted to it."
Nunez then lined a two-out single that looked like it would bring around Cano with the tying run.
Giants left fielder Juan Perez -- who grew up in the Bronx during the recent Yankees dynasty, practicing on the Macombs Dam Park diamonds -- came up firing with a rocket to the plate, making sure the day remained bittersweet for both Pettitte and Rivera.
"I appreciate this day, what the organization did," Rivera said. "The fans that were here supporting me, that was good. At the end, it wasn't that great, because we lost the game."