SAN FRANCISCO (AP) _ The New Orleans Saints have bucked the odds all season, and they did it again in San Francisco with a come-from-behind win. Terry Allen scored on a 1-yard run with 46 seconds left as the Saints clinched just their sixth winning season in the last 34 years with a 31-27 victory over the San Francisco 49ers on Sunday. New Orleans (9-5) trailed 27-17 with six minutes to play, but Aaron Brooks led the Saints on two late scoring drives to keep their NFC West title hopes alive. They beat the 49ers for the third straight time and kept pace with the St. Louis Rams (9-5), who beat Minnesota 40-29. The Saints danced and cheered on the sideline as they celebrated their first winning season since 1992 _ also the last year they made the playoffs. The 49ers defense that held its last three opponents to 30 total points was unable to cope with Brooks' scrambling. Brooks, who was terrible in the air but deadly on the ground, led New Orleans to 17 points in the fourth quarter and continually stayed just inches away from a sack or an interception. Brooks completed just two of his first 12 passes and finished 12-of-29 for 203 yards, but he rushed for 108 yards and completed several big passes in the fourth quarter. New Orleans also weathered a huge game from 49ers quarterback Jeff Garcia, who passed for 305 yards and two touchdowns and also ran for two scores. The 49ers' three-game winning streak was snapped even though San Francisco dominated the first three quarters and scored two touchdowns in the fourth. Garcia, who was 25-of-38 but threw two interceptions, hit Terrell Owens with a 69-yard TD pass with 8:27 left that put San Francisco up by 10 after a missed extra point. New Orleans cut the lead when Brooks nimbly sidestepped two rushers and hit Willie Jackson for a 22-yard score with 5:46 left. After San Francisco punted, Brooks engineered a 68-yard drive, converting a fourth-and-4 with a 10-yard run and hitting Keith Poole with a 22-yard pass before Allen's 1-yard run. But the game nearly turned twice on two controversial plays in the final 80 seconds. The 49ers thought Chad Morton fumbled out of the end zone when he was tackled at the 1, but video replay disagreed. Then Terrelle Smith fumbled on a 1-yard dive attempt with a minute to play, but the Saints recovered. Allen, who got his first significant action since signing with the Saints last month, scored on the next play and finished with 80 yards rushing. It was New Orleans' only lead of the game. Garcia marched the 49ers on two lengthy first-half scoring drives that ended his short TD runs. San Francisco held the Saints to 98 total yards and 3 yards passing, and led 14-3 at halftime. But Brooks led the Saints on two scoring drives to open the third quarter. Charlie Garner's fumble set up New Orleans' first touchdown on Andrew Glover's 15-yard reception.