LOS ANGELES – If only Don Mattingly knew that his words would work so well, he probably would have said them a lot earlier.

The Dodgers’ dramatic 3-2 victory over the San Francisco Giants on Monday night at Dodger Stadium was the team’s sixth in a row since the manager delivered what catcher A.J. Ellis referred to as a call for “accountability” last Wednesday in San Diego.

Thanks to their winning streak, the Dodgers have survived all the way until the day of their 161st game, still with a mathematical shot to reach the postseason, even when it seemed to be over a week ago.

Elian Herrera’s game-winning single in the bottom of the ninth capped the thrilling victory, which kept the Dodgers within two games of the St. Louis Cardinals for the National League’s second wild-card spot. There are only two games to go, so the Dodgers have no margin for error.

The Dodgers need to win their last two against the Giants and the Cardinals must lose their next two against the Cincinnati Reds, and then the Dodgers have to beat the Cardinals in a tie-breaker on Thursday at Dodger Stadium.

It’s their only chance, but at least it’s a chance.

Which, be honest, is more than you thought the Dodgers would have a week ago.

Ellis said the tide turned when Mattingly called a meeting before the second game of the three-game series against the Padres.

“We had a pretty tough meeting in San Diego and he laid it out for us,” Ellis said. “He kind of called us on the carpet and put us in a spot to take our own personal accountability for what’s going on. It was a good meeting. Since then I think guys have looked themselves in the mirror and we’ve played better. I give a lot of credit to him.”

The Dodgers haven’t lost since. Their six-game winning streak equals their longest of the season, and it has pushed the Cardinals to the penultimate game of the regular season, with the champagne still corked.

“The guys kept fighting,” Mattingly said. “It’s a testament to the guys in that room that they are not giving up. We just have to take care of our business and hope for some help.”

Midway through Monday’s game the Dodgers knew they weren’t getting the help they needed, as the Cardinals beat the Reds. That meant the Dodgers would be eliminated if they lost. Still, they were clinging to a 2-1 lead for much of the game, thanks to Andre Ethier’s two-run homer in the fourth.

But the Giants tied it in the eighth, on Angel Pagan’s double and Marco Scutaro’s RBI single.

Dodgers closer Brandon League worked a scoreless ninth to set up the heroics in the bottom of the inning.

Facing Santiago Casilla, Hanley Ramirez led off with a single. Shane Victornio bunted him to second. Luis Cruz singled, but Ramirez was held at third. An intentional walk to Ellis loaded the bases for Herrera, who had just entered the game in a double switch.

Herrera smoked a line drive toward the second baseman, Scutaro, who leapt, but the ball glanced off his glove and trickled into the outfield as the winning run scored. The Dodgers mobbed Herrera, celebrating at least one more day of meaningful baseball.

“It’s not over yet,” Ellis said. “We are still in this. The Cardinals are playing a strong team that’s still fighting for home field advantage in the playoffs, and a bitter rival at that. It’s definitely not over. The Reds have a lot to play for and so do the Cardinals. We’ll be out here watching and hopefully we can take advantage.”