OAKLAND, Calif. — Mariano Rivera had warmed up several times already before finally entering to a standing ovation for his likely Oakland Coliseum farewell. In the 18th inning, 5 1/2 hours after first pitch, the potential winning run aboard and just about everybody eager to call it a day.

With no room for error, Rivera allowed Nate Freiman's game-winning, broken-bat single and the Oakland Athletics beat the New York Yankees 3-2 on Thursday to complete a three-game sweep.

"We definitely didn't want it to end like that," Rivera said. "It's give and take. A game like this, you don't want to lose it. It's the way it happened."

As a day game after a night game turned into a night game after a day game, John Jaso singled off Preston Claiborne (0-1) to start the decisive rally and went to third on Seth Smith's soft single to shallow left field against Rivera.

Rivera issued only the 39th intentional walk of his 19-year career to Jed Lowrie before Freiman ended the 5-hour, 35-minute game on New York's getaway day to Anaheim for a weekend series with the Angels.

"A little broken-bat blooper over the third baseman, and the other one the same place," Rivera said. "You can't do anything about it."

Freiman knew he had it, raising his right arm in triumph.

"I knew that was not getting to the left fielder. I knew it was falling," he said.

Moments later, Freiman received a whipped cream pie in the face to celebrate his first career game-ending hit. He had entered the game in the top of the 16th.

"I think it's probably a little more frustrating because you can look at how you had an opportunity here and an opportunity there," Yankees manager Joe Girardi said. "A lot of guys probably look at that, but it doesn't change the result."

Each team used seven pitchers and threw 255 pitches. In all, 137 batters came to the plate – short of the season high of 156 during Oakland's 19-inning win over the Angels in April and also the 20-inning game between the Marlins and Mets last Saturday.

"It was very taxing even winning the game. To lose could have been demoralizing," A's manager Bob Melvin said. "These are awful games to lose."

The AL West-leading A's (41-27) won their 11th in a row at home, 21st in 26 overall, and moved a season-best 14 games above .500 to extend their best start since 1990. They became the first American League team to play two 18-inning games in one season since Oakland and the Washington Senators did so in 1971.

New York made a dramatic play in the bottom of the 15th to keep the game going.

Pinch-hitter Coco Crisp singled to left with one out and Wells made a perfect throw to catcher Chris Stewart, who blocked the plate and absorbed a collision to prevent Brandon Moss from scoring the winning run.

The A's had already begun streaming out of the dugout to celebrate.

The Yankees had runners in scoring position in each of the extra innings through 14, stranding 11 baserunners. They left 13 on base in all while dropping their seventh in a row at the Oakland Coliseum.

Chavez fanned Youkilis and Wells with two on to end the 13th, then Hafner and Wells in the 15th.

Jerry Blevins escaped a bases-loaded jam in the top of the 11th with two strikeouts. Pat Neshek worked out of trouble with runners on first and second in the 12th.

Robinson Cano hit a two-run homer in the first as New York ended a season-long five-game stretch without a long ball, but the Yankees didn't score again on another day of missed opportunities.

"We had plenty of opportunities and we couldn't cash in," Stewart said. "We were just unlucky."

After Smith's tying, two-out double in the third, Oakland didn't reach base again until Jaso's bloop single leading off the ninth.

Oakland won the season series 5-1 for its second-best mark against the Yankees in franchise history. The 1990 club went 12-0.

The A's tied it at 2 in the third on a close play at the plate. Smith doubled off the wall in right and the relay throw was on target to Stewart, who tagged Jaso with his glove but had the ball in his bare hand.

Jaso was called safe by plate umpire CB Bucknor, drawing an argument from Girardi.

"I caught the ball against my chest, with both my glove and hand," Stewart said. "I had the ball in my hand and I thought I had tagged him with both but he said he saw the ball outside of the glove. I didn't think I had my hand and glove separated. I thought they were together."

Earlier in the inning, Derek Norris' RBI groundout scored Chris Young, who drew a leadoff walk. Eric Sogard followed with a single before the A's pulled off a double steal.

Jarrod Parker, riding a three-start winning streak for Oakland, was helped by a pair of double plays in the first four innings.

Hiroki Kuroda's winless stretch reached five starts since he beat Toronto on May 17. He became the third Japanese-born pitcher with 1,000 innings in the majors, joining Hideo Nomo and Tomo Ohka.

Girardi bumped Jayson Nix up to the No. 2 spot in the batting order from eighth a night earlier to shake things up and get the Yankees going, but Nix went 1 for 5 with a strikeout to end the 12th.

It was the longest day game in Coliseum history.

NOTES: Yankees captain Derek Jeter had his surgically repaired left ankle examined by Dr. Robert Anderson in Charlotte, N.C., and was cleared to resume baseball activities and running. .. Rivera received a surfboard and a bottle of white wine from Napa Valley from the A's in a pregame ceremony, along with a $10,042 donation to his foundation. ... New York agreed to contract terms with Notre Dame 3B Eric Jagielo, who signed for $1,839,400. He was the 26th overall pick in last week's draft and one of three first-round selections by the Yankees.