San Francisco’s Angel Pagan, second from left, celebrates with teammates after hitting a walk-off single in the 11th inning to beat Arizona.

SAN FRANCISCO — Arizona manager Kirk Gibson went out to first base to see why a call got reversed. He wound up out of the game.

Gibson was ejected for the second time in four days and watched, from his office, as Arizona lost to the San Francisco Giants 3-2 in 11 innings Sunday.

The Diamondbacks had a chance to go ahead in the 10th when Willie Bloomquist doubled with one out and, following the second out, Paul Goldschmidt was intentionally walked.

Aaron Hill, who entered the game with a .333 average over the previous six weeks, hit a grounder to Buster Posey at first base. Posey bobbled the ball, but recovered in time to deliver an underhanded toss to pitcher George Kontos, who had trouble finding first base and double-stepped.

First base umpire Tom Hallion, who tossed Gibson on Thursday for arguing a call at home, originally called Hill safe.

Giants manager Bruce Bochy asked if Hallion could get help on the play. Hallion obliged, talking with the crew before reversing his call, ending the inning.

“I just wanted to question the call,” Gibson said. “He didn’t want to hear about it, so I got thrown out.”

Wade Miley, who could not get out of the second inning of his last start for Arizona, pitched seven strong innings Sunday.

“You want to get back out as soon as possible,” Miley said. “But you can’t worry about the last time out.”

Miley was lifted for pinch-hitter Eric Chavez, who hit a sacrifice fly to help the D-backs tie the game at 2 in the eighth. A.J. Pollack also singled home a run for Arizona, which fell 8ƒ games back in the wild-card race.

“We have not swung the bats very well at all, especially in the good situations,” Gibson said. “We’re not in a good streak right now.”

Angel Pagan hit a winning single in the 11th off Joe Thatcher (3-2) after Hector Sanchez singled and Gregor Blanco reached safely on a sacrifice bunt. Pinch-runner Ehire Adrianza beat the throw home.

Javier Lopez (3-2) got the win.

“You know it’s going to be a close game,” Miley said. “So you want to put up zeros, and then you want to hold it at 2-0 to give your team a chance.”

Miley allowed two runs on five hits. He walked two and struck out three.

“I felt like I was struggling,” he said. “But I was getting outs.”

Matt Davidson walked to lead off the ninth for the D-backs pinch-runner Tony Campana was caught stealing. Miguel Montero followed with a single but was stranded.