Longoria drove in three runs, including two on a home run in the 13th inning, and the Tampa Bay Rays beat the Oakland Athletics, 7-6, on Monday night.
"I wasn't really thinking about anything except to stay out of the double play," Longoria said of his game-winning blast. "I wanted to get him over somehow. I've been swinging the bat good lately. We all know we can play and we expect to win."
Jason Hammel (3-2), pitching for the first time in 11 days, threw three scoreless innings for the win. He struck out three of the final four batters he faced after walking two and giving up a hit.
"I talked to Hammel before the game out in the outfield," Rays manager Joe Maddon said. "I said, 'Listen, this stinks, but we need you to be ready. At some point you're going to be needed and you'll come through.' That time came today. He pitched great. He hasn't been out there for some time and he goes and throws strikes."
Hammel was removed from the starting rotation when Scott Kazmir came off the disabled list on May 4. Hammel made just his 13th career relief appearance on Monday.
"Basically he came out and asked how I was feeling," Hammel said of his pregame meeting with Maddon. "I was thinking to myself I was pretty darn near insanity trying to get in there every day. He told me to keep myself ready and I'd be a big part of things. I was a big part of it tonight."
Hammel started the 10th inning by walking Bobby Crosby before Carlos Pena turned a popup on a bunt attempt into a double play. Hammel pitched out of a minor jam in the 11th, when the A's had two runners on with one out.
"I was too excited to be in there that I almost forgot what to do," Hamel said. "I'm still learning, but it's all about doing my job and getting outs. No matter when or where you pitch, you still need to throw strikes."
Hammel does have two Minor League saves in the seven career appearances he made in 2002 and 2003.
"I was coming back from an elbow injury and working myself back into the rotation," Hammel said. "That was six years ago, though."
Troy Percival pitched the bottom of the 13th for his 12th save.
Longoria hit a 2-1 delivery from Chad Gaudin (3-3) well up into the left-field bleachers. Pena, who singled to open the inning, scored ahead of Longoria, who is 8-for-18 in his last four games following a 7-for-50 slump.
"He seems to be getting back on track," Maddon said. "He has a more aggressive swing. He crushed that home run."
Akinori Iwamura doubled home Jason Bartlett in the top of the seventh to give the Rays a 5-4 lead, but James Shields faltered in the eighth, giving up a two-out single to Ryan Sweeney that tied it again.
Sweeney and A's slugger Frank Thomas combined to do most of the damage, getting five of the eight hits and driving in four of the five runs Shields allowed in 7 2/3 innings. Shields walked one and struck out four.
"I don't feel like this is a bad outing for me," Shields said. "It was just two home runs, no big deal. It happens. I'll bounce back."
Gary Glover came on to finish the eighth, stranding a pair of runners in the process. He's stranded 11 of the 12 runners he has inherited this season. J.P. Howell pitched a scoreless ninth.
Eric Hinske, who spent a year in the A's organization, contributed his eighth home run of the season, a two-run shot in the fifth inning that put the Rays on the board.
Cliff Floyd also drove in a run for the Rays.
Rick Eymer is a contributor to MLB.com. This story was not subject to the approval of Major League Baseball or its clubs.