Cornerback Gary Green returned an interception 41 yards for a touchdown with 3:24 left tonight to give the Los Angeles Rams a 27-20 victory over the San Francisco 49ers and assure the Rams of at least a wild-card berth in the National Football League playoffs.

The Rams (10-4) are two games ahead of the 49ers in the NFC West. San Francisco, the defending Super Bowl champion, fell to 8-6 and probably will need victories in its last two regular season games to reach the playoffs.

"We've come from behind before this season and now we'll have to do it again," 49ers Coach Bill Walsh said.

The Rams trailed three times before tying at 20 with 5:08 left in the fourth quarter. Dieter Brock threw a 39-yard touchdown to Henry Ellard, who grabbed the ball after it was tipped by defender Dwight Hicks. Mike Lansford's kick tied it.

On the 49ers' next possession, Joe Montana threw a short pass over the middle to running back Carl Monroe, but the ball popped away and into Green's hands. And he was on his way to the winning touchdown.

San Francisco's final possession ended when defensive end Gary Jeter sacked Montana, forcing a fumble, which he recovered.

"We never blinked at all," Rams Coach John Robinson said. "We believed all along that if we kept the score close, we'd win."

Jerry Rice, the 49ers' rookie wide receiver, set a team record with 241 yards on 10 receptions. He caught a 66-yard touchdown pass early in the third period and his 52-yard reception early in the fourth quarter set up Montana's touchdown pass to fullback Roger Craig, which broke a 13-13 tie.

Montana passed seven yards to Dwight Clark for a touchdown on the first play of the second quarter. The Rams got a 25-yard field goal from Lansford in the second period and trailed, 7-3, at halftime.

Ron Brown sent the Rams ahead for the first time, opening the second half with an 86-yard kickoff return for a touchdown.

The 49ers regained the lead 1 1/2 minutes later on the touchdown by Rice. But the 49ers' Ray Wersching had a streak of 150 consecutive extra-point kicks broken when Shawn Miller blocked his attempt.

The Rams tied on Lansford's 29-yard field goal, set up by a 41-yard run by Eric Dickerson, who signed a four-year contract extension earlier in the day. Financial terms were not announced, but the Rams said Dickerson, who had two years left on a four-year, $2.2 million contract, would be "one of the highest-paid running backs in the NFL."

"We were sick and tired of hearing how great the 49ers were and what a bunch of slobs we were," he said.