SAN DIEGO (AP) -- The St. Louis Rams were 4 yards away from another upset.
Journeyman quarterback Shaun Hill dropped back to pass and Kenny Britt flashed across the middle.
Strong safety Marcus Gilchrist swooped in and it was game over.
Gilchrist intercepted journeyman Shaun Hill at the goal line with 56 seconds left to preserve the Chargers' 27-24 victory against the Rams that helped tighten the AFC West race.
"I feel very bad for our football team considering the way they played," coach Jeff Fisher said. " We had an opportunity to win at the end of the game, and you can't take that away. That was a tough one. There's no blame to be placed on anyone."
Gilchrist jumped the route as Hill tried to force a pass to Kenny Britt, who also was covered by Shareece Wright, on second-and-goal from the 4.
Hill had beaten Gilchrist on a 7-yard TD pass to Stedman Bailey with 2:04 left that pulled the Rams within three points.
St. Louis got the ball back at the Chargers 40 after a long punt return by Tavon Austin and a 27-yard pass from Hill to Britt gave the Rams the ball at the 6. Benny Cunningham gained 2 yards before Hill was intercepted.
"They had good coverage on my primary, and Kenny just kind of flashed and I pulled," Hill said. "It was just a reaction.
"The coaches put the ball in my hands with a chance to win the game, and I appreciate that," Hill said. "I let them down. There's no way you can sit there and second-guess the play calling. If you're going to second-guess anything, second-guess the guy who didn't execute the play, and that's me."
The Rams (4-7) were trying for consecutive wins for the first time this season, having upset Denver a week earlier.
"Until we put a couple of wins in a row together, it's going to be hard for us," Fisher said. "We are not going to change anything."
Ryan Mathews had a 32-yard touchdown run and linebacker Andrew Gachkar scored on a 13-yard fumble recovery 21 seconds later for the Chargers (7-4).
Philip Rivers shook off a 99-yard interception return for a touchdown by Janoris Jenkins and threw a 29-yard touchdown pass in the fourth quarter to Keenan Allen, who earlier had two turnovers.
The Chargers' third-quarter outburst started when Mathews took a delayed handoff and picked his way up the middle to cap their first possession of the second half for a 13-10 lead. It was his first touchdown since opening night. Mathews sprained his right knee in Week 2 and missed the next seven games.
On the second play of the ensuing Rams drive, Chargers end Corey Liuget hit Hill as he was trying to pass, knocking the ball loose. Gachkar alertly swooped in, picked up the ball and scored for a 20-10 lead.
The Rams benefited from a fumbled punt when Chargers returners Allen and Chris Davis collided after Allen called for a fair catch, with Alex Bayer recovering. Tavon Austin scored on a 6-yard score on an end-around to pull the Rams to 20-17.
Allen then fumbled after a reception and long run, with St. Louis' Rodney McLeod recovering.
Allen caught a screen pass from Rivers and picked his way through the defense to give San Diego a 27-17 lead with 8:09 to play.
Rivers was playing a week after teammate Antonio Gates revealed the QB had "a very severe rib injury" that coach Mike McCoy later denied.
The Chargers had a third-and-goal from the Rams 8 early in the second quarter when Jenkins outmuscled Allen for the ball and outraced everyone down the field to give the Rams a 10-3 lead.
The Rams blew the chance to score 10 more points in the half as Greg Zuerlein's 36-yard field goal attempt was blocked by Darrell Stuckey, and a 51-yard TD pass from Hill to Britt was negated by a facemask penalty against left tackle Greg Robinson.
The Rams had to punt and the Chargers had enough time to move downfield for a 48-yard field goal by Nick Novak to pull to 10-6 at halftime.