John Robinson never was sure the Los Angeles Rams were quite as good as their 7-0 start, and he hoped they weren't as bad as their subsequent 2-4 slump, so he figured to find out where they belonged in the National Football League hierarchy Monday night.

As the Rams coach walked through the team's hotel lobby Monday morning he was asked for a prediction.

"Twenty-one to 17," he blurted without hesitation.

His gut feeling about his funny little football team was pretty close to correct. His faith was fulfilled as the Rams scored 17 points in the fourth quarter at Candlestick Park and pulled out of their nosedive with a 27-20 victory over the San Francisco 49ers.

Officially, the guard hasn't changed in the NFC West. All the Rams clinched was a wild-card spot, but that's a big 10-4 they put up in the standings, and they should march right into the playoffs. With a two-game lead and two to play, they can wrap up their first division title since 1979 by defeating the St. Louis Cardinals at Anaheim Stadium on Sunday.

In the last month and a half they fumbled and stumbled haplessly as their four-game lead shrank to one, setting up Monday night's showdown with the defending Super Bowl champions before the second-largest crowd in 49ers history, 60,581. The 49ers were 10-point favorites.

Three times Monday night the Rams fell behind as an old nemesis, Joe Montana, threw three touchdown passes and rookie Jerry Rice caught 10 passes for a club-record 242 yards. But three times they came back -- each time with explosive impact:

*Ron Brown returned the second-half kickoff 86 yards for a touchdown.

*Dieter Brock passed to Henry Ellard, on a tipped pass touched by 49ers Ronnie Lott and Dwight Hicks, 39 yards for a touchdown.

*Gary Green intercepted a pass off the hands of 49ers receiver Carl Monroe and returned it 41 yards for a touchdown.

Bill Walsh, the 49ers' coach, said, "I must congratulate the Rams for what appears to be a fine season. San Francisco lost a tough game tonight for a number of reasons, and unfortunately one of those reasons was the tipped touchdown pass.

"Defensively, they used good tactics. They changed up their defensive look a number of times."

The Rams put away some ghosts Monday night. Montana had thrown 237 passes without an interception against them, spanning parts of seven games since 1982, and what a time he picked to throw one.

The 49ers, leading by 13-10, had a third down at the Rams three, and seemed about to put the game away. But Vince Newsome was in the right place -- the end zone -- and he certainly chose the right time -- when Montana tried to force the ball through to tight end Russ Francis.

Newsome caught it cleanly and fell to his knees for a touchback.

From there the Rams tied it on the second of Mike Lansford's two field goals, spotted the 49ers a 20-13 lead on Montana's one-yard bootleg pass to Roger Craig and roared back again on the Ellard and Green touchdowns.

The defense that had forgotten how to make things happen remembered Monday night. Besides intercepting Montana twice, they finished it off with a flourish when end Gary Jeter fought his way past Bubba Paris to sack Montana, caused him to fumble and then recovered to kill the 49ers' last hope.

"We had our backs to the wall," Robinson said, "and when you have your backs to the wall people see the real you."

Montana, who completed 26 of 36 for 328 yards, including an improvised 66-yard pass to Rice, said, "They didn't really beat us. We outplayed the Rams."