Bobby Cox took the familiar walk toward the clubhouse in the second inning Friday night, after yet another ejection for the longtime Atlanta Braves manager.

He wouldn’t have minded sticking around a little longer for this one.

Count the obstacles that blocked the Braves’ path before they rallied to defeat the Giants 5-4 in 11 innings at AT&T Park in Game 2 of the National League Division Series:

They fell behind 4-0 after two innings, as starting pitcher Tommy Hanson served up a three-run homer to Pat Burrell in a wobbly first inning.

The Braves faced the prospect of making a comeback against a Giants bullpen that hadn’t allowed a run in its final 24 innings of the regular season.

Then Atlanta watched its own closer, Billy Wagner, leave with an oblique injury in the bottom of the 10th.

It seemed fitting that center fielder Rick Ankiel — who started a career comeback in 2005 when he converted from a pitcher to outfielder — delivered the go-ahead homer off Ramon Ramirez in the top of the 11th that pulled Atlanta even in the best-of-five series as it moves to Turner Field for Game 3 on Sunday.

“You can never figure out baseball, for sure,” Cox said. “But I as talking to our guys before the game, (saying) ‘Win this one and the momentum swings the other way.’ “

The Braves appeared on the verge of elimination before Friday’s comeback, and Cox’s long managerial career seemed headed for a sad conclusion.

He’s retiring at season’s end, putting the wraps on a 29-year managerial career, 25 of which has been spent leading the Braves.

Cox ranks fourth on the all-time managerial win list, but he’s just as well-known for the major league record he holds for getting the thumb.

Friday’s ejection was the 161st of his career (his third in the postseason after 158 in the regular season), and unless his temper boils over again in this postseason, Giants fans may have seen him get tossed for the final time.

After Alex Gonzalez was called out on a close play at first — replays showed first baseman Aubrey Huff may have pulled his foot off the bag — Cox went out to jaw with first-base umpire Paul Emmel.

He turned his attention to home plate umpire Paul Nauert before picking up his argument with Emmel.

Cox slammed his hat to the ground, which got him tossed. The crowd serenaded Cox with a chant of “Bobby! Bobby! Bobby!” as he made his way toward the visitors’ clubhouse.

Emmel was umpiring second Thursday night when he wrongly ruled Buster Posey safe on a stolen base attempt. Posey wound up scoring the game’s only run as the Giants took Game 1.

“Well, I brought that up,” Cox said. “It was the only run that scored (Thursday) night. (Posey) was out. Still, I respect umpires, and they’re human. I’m not always right (either).”

Wagner hurt his oblique while fielding Andres Torres’ sacrifice bunt in the 10th. Cox said Wagner likely is out for the rest of the series.

Kyle Farnsworth relieved Wagner and escaped a bases-loaded jam by getting Posey to ground into an inning-ending double play.

Then Ankiel delivered his towering blast to right in the 11th.

“It’s the biggest homer of my career by far,” Ankiel said. “To be honest, I didn’t even want to run the bases. I wanted to be with the guys.”