Stafford threw a 7-yard touchdown pass to Odell Beckham Jr. with 57 seconds left immediately after completing a 5-yarder to Beckham on a fourth-and-5. After Los Angeles failed on a 2-point conversion, the Ravens - playing a third straight game without injured quarterback Lamar Jackson - never got close enough for a field-goal try.
The victory pushed the Rams (12-4) to the cusp of their second straight NFC West title. Arizona needed to beat Dallas later Sunday to avoid elimination.
At one point this season, Baltimore was 8-3 and the top seed in the AFC. The Ravens (8-8) have since lost five straight, their longest skid since a nine-game run in 2007 under Brian Billick paved the way for current coach John Harbaugh to take over in 2008.
Four of those defeats during this slump have come by a total of five points.
The loss ousted Baltimore from the AFC North title hunt. The Ravens were not officially eliminated from the playoff chase, but to get in as a wild card they'll need a win next week and a whole lot of help.
Facing a depleted defense that was coming off a humbling performance in Cincinnati one week earlier, Stafford was intercepted twice by Chuck Clark in the first half, the first pickoff returned 17 yards for Baltimore's only touchdown. The quarterback also lost a fumble while being sacked in the third quarter.
The Rams trailed 16-7 before Stafford directed a 55-yard drive that produced a 1-yard touchdown run by Sony Michel with 12:09 remaining. Baltimore responded with a field goal to make it 19-14 with 4:33 left.
That left Stafford with more than enough time to win it. He launched the game-winning 75-yard drive by completing a 15-yard pass to tight end Tyler Higbee and a 24-yarder to Cooper Kupp. He finished the march with a pair of sharp throws to Beckham, the last one in the front corner of the end zone.
Stafford completed 26 of 35 passes for 309 yards and two touchdowns.
Starting for Jackson, Tyler Huntley went 20 of 32 for 197 yards in his third NFL start. He missed last week while on the COVID-19 reserve list.
One week earlier, Cincinnati quarterback Joe Burrow pierced the Ravens depleted secondary for 525 yards and four touchdowns in a 41-21 blowout. Although Stafford rallied the Rams to a victory, he was severely tested by a defense that has struggled without injured cornerbacks Marcus Peters, Marlon Humphrey and Anthony Averett.
Down 10-0 late in the second quarter, the Rams used a 34-yard interception return by Jordan Fuller and an 18-yard touchdown reception by Kupp to close to 10-7 before Justin Tucker kicked a field goal for Baltimore just before halftime.
Andrews set a Ravens single-season record for yards receiving, breaking the mark set by Michael Jackson during the team's first year in Baltimore after relocating from Cleveland.
Andrews has 1,276 yards this season. eclipsing Jackson's 1,201 in 1996. Andrews also stands just four catches shy of matching the franchise single-season record of 103, set by Derrick Mason in 2007.
Ravens: C Bradley Bozeman dressed for the game, but ended up watching from the sideline while wearing a mask despite going the entire week without being listed on the injury report. Trystan Colon started in his place.
Rams: Wrap up the regular season at home against the San Francisco 49ers, who whipped LA 31-10 on Nov. 15.
Ravens: The rival Pittsburgh Steelers come to town for the season finale.