NEW ORLEANS — With five wins in their previous six games, the resurgent New Orleans Saints were feeling like they were on the cusp of doing some big things going into their final six-game stretch of the season.

Things certainly set up nicely early Sunday when three teams that were just one game ahead of the Saints in the NFC wild-card race all lost before their game with the San Francisco 49ers even began.

It looked even better when Saints cornerback Patrick Robinson intercepted 49ers quarterback Colin Kaepernick just 38 seconds before halftime to give his offense a chance to extend a 14-7 lead.

But at that point it all began to unravel for the Saints when they gave up three touchdowns — two by the 49ers’ defense — in less than four minutes of clock time that led to a 31-21 loss in the Mercedes-Benz Superdome.

But just like that, the Saints (5-6) wasted the opportunity and remained one game out of the final playoff spot with a quick turnaround coming this week against the Atlanta Falcons in the Georgia Dome on Thursday night.

“We had to win,” Saints quarterback Drew Brees said. “It’s all right there in front of us.”

But it all went wrong just seconds after Robinson’s interception off Kaepernick, a second-year pro who was making just his second career start.

The Saints, who had come back from an early 7-0 deficit to grab a 14-7 lead on touchdowns of 6 and 10 yards from Brees to tight end David Thomas and wide receiver Marques Colston were in business again at their 44.

On the second play of the series, Brees tried to squeeze a throw in to tight end Jimmy Graham when 49ers linebacker Ahmad Brooks intercepted and returned the pass 50 yards for a score with 22 seconds to go to tie the game at 14-14.

“From what I saw, he did a great job,” Brees said of Brooks. “He caught that thing on his fingertips. He dropped out (into coverage) and we were trying to fit it in there to Jimmy. He just made an extremely athletic play.”

Coming out of halftime with momentum, the 49ers (8-2-1) regained the lead with an 80-yard TD drive capped by a 6-yard scoring pass from Kaepernick, who had a 7-yard TD run to open the scoring, to running back Frank Gore.

Then, the 49ers’ second-ranked defense struck again when Brees was sacked by defensive tackle Justin Smith before strong safety Donte Whitner picked off a pass and returned it 42 yards for another touchdown.

That pushed the 49ers’ lead to 28-14 with 11:30 left in the third quarter.

While that’s usually more than enough time for the Saints to come back, the 49ers’ second-ranked defense allowed just one more touchdown — a 2-yard pass from Brees to fullback Jed Collins — the rest of the way for the win.

That score came midway through the third quarter, which means the 49ers, who got a 27-yard field goal from David Akers in the fourth period, held the Saints scoreless for the final 22 minutes.

“Obviously, what was glaring was the two turnovers that resulted in touchdowns for them,” said Brees, who completed 26 of 41 passes for 267 yards with three TDs and the two picks. “That can’t happen, especially the first one — the one there at the end of the first half where you’re trying to go down and get something for your team.

“You certainly can’t give it to them inside of 30 seconds and let them get an easy one,” he added. “Obviously, that was a big momentum swing.”

Saints interim coach Joe Vitt saw it differently, however.

When asked if the interception and touchdown by Brooks was the turning point in the game, considering the Saints could have had a 10- or 14-point halftime lead, Vitt said it wasn’t.

“Absolutely not,” he said. “It’s one play at a time, one series at a time, one quarter at a time, one half at a time. If we let one play affect us the rest of the game, we’re unprofessional.

“We’ve overcome things like that before. It’s the nature of our game.”

The 49ers’ defense made sure it didn’t happen, however, as it sacked Brees five times — all in the second half after Kaepernick gave the Niners the lead again in directing the 80-yard TD drive to start the third quarter.

Justin Smith, Brooks and outside linebacker Aldon Smith each had 11/2 sacks. Aldon Smith now leads the NFL with 161/2 sacks.

But Kaepernick, who was starting his second game since Alex Smith suffered a concussion two weeks earlier, did his part in completing 16 of 25 passes for 231 yards with one TD and one interception.

Smith was cleared Saturday by doctors to play, but 49ers coach Jim Harbaugh decided to stick with Kaepernick, who also ran for 27 yards on six carries in leading the Niners to 375 total yards.

Ironically, it was the first time the Saints had held an opponent to under 400 yards in 11 games this season.

“I thought he did a good job managing the game,” Saints weakside linebacker Jonathan Vilma said. “He didn’t force any passes. He did exactly what they asked him to do.”

“Colin played well and in a tough environment,” Harbaugh said. “He acquitted himself very well.”