ST. LOUIS -- John Lannan may have given up two runs in eight innings to the Cardinals on Friday night, but it's one pitch to Khalil Greene that the lefty couldn't get out of his mind.

Lannan, five outs away from his first win since Aug. 5, fell behind the Cardinals' pinch-hitter with one out in the eighth and gave up a solo homer to tie the game.

That set the stage for Albert Pujols' walk-off homer in the bottom of the ninth off Jason Bergmann as the Cardinals came from behind to stun the Nationals, 3-2, on Friday night at Busch Stadium.

Lannan had given up 23 earned runs in his previous 25 innings, but he looked like the stellar pitcher that the Nationals had seen for much of the season. He recorded 17 ground-ball outs and gave up four hits, with the fourth and final one being the game changer.

"It's definitely a step in the right direction and I can definitely build off of it, but right now, I'm still thinking about that one pitch," Lannan said. "Tomorrow, talk to me again and I will probably be in a better mood. But right now, I'm still a little ticked off.

"I, obviously, wasn't trying to get 3-0 on him. I got 3-1 and I threw a ball down the middle. It was a mistake and that's where you tip your cap, a 3-1 fastball right down the middle, coming off the bench. It was my fault."

The Nationals, who had won five of six road games coming in, took a 2-1 lead in the seventh on catcher Josh Bard's RBI double. And with the way Lannan was cruising on the hill, it looked like Washington was going to send the home team to consecutive losses for the first time since July 25-26.

But with one swing of the bat, the game was tied.

"That was more like what we saw earlier in the year," said interim manager Jim Riggleman. "He was outstanding against a good hitting ballclub. He got a lot of ground balls. He pitched a great ballgame. He got behind on Khalil Greene, and Khalil has a little power. And he had to put one in there, and Khalil took advantage of it. That was the big blow."

Riggleman chose not to use closer Mike MacDougal in the ninth with the score tied, because the righty had worked 1 2/3 innings Thursday in Chicago and it wasn't a save situation.

Bergmann, who had allowed seven runs in his last 2 1/3 innings coming in, won the unlucky job of getting to face Pujols, Matt Holliday and Ryan Ludwick with the score tied in the bottom of the ninth. But Pujols made sure it didn't get past him, launching a 1-1 pitch from the righty deep into the St. Louis night to end the game.

"I was really pumped up and amped to face Pujols in a tough situation, and I threw a pitch that I regret throwing right now," Bergmann said as he sat and stared into his locker. "For me, right now, it's only a couple of minutes after it happened and I'm not very happy with both the location and the pitch. In hindsight, I wouldn't have thrown it. I'd like to have thrown something different, and hopefully the result would have been a lot different."

Pujols looked bad in three at-bats against Lannan, grounding out twice on comebackers to the mound and flying out to right. But as the stars usually do, Pujols rose to the occasion.

"When he goes up there four or five times a night, there's a good chance he is going to get you sooner or later," Riggleman said. "Bergmann just happened to be the guy on the mound when he got us."

The Nationals saw a different John Smoltz than the one that they pummeled for five runs and seven hits in five innings in his Red Sox debut on June 25. Picked up by the Cardinals last week, the future Hall of Famer limited Washington to one run in six innings and departed with the score tied at 1.

Despite the tough loss, the Nationals still have a winning record (14-12) in the month of August and proved to themselves that they can hang with one of the best teams in the league. They sit just two games under .500 at 20-22 since Riggleman took over on July 13, and the interim coach already seems to have planted a winning attitude in his players.

"Earlier in the year when we were losing a lot of ballgames, it was almost like 'Oh well, just another loss,'" said Willie Harris. "But now I think it hurts us more to lose games like that, because we know we can win. We feel like we can win, especially after we won those eight games in a row. We feel like we can play right along with anybody.

"We played against a championship-caliber team right there. We're going to see those guys go pretty sure deep into the playoffs -- if not win the whole thing -- and we were right there with them. That lets you know the character we have here in this clubhouse."