MIAMI GARDENS, Fla. -- Ryan Tannehill watched the final play from the sideline, hopping anxiously as an opponent's desperation heave hung in the air, then letting out a jubilant scream when a teammate swatted the ball to the turf.
At the end of a dismal week, the Miami Dolphins finally had something to celebrate.
Brent Grimes broke up Philip Rivers' final pass in the end zone as time expired, and the embattled Dolphins beat the San Diego Chargers 20-16 Sunday.
Tannehill threw for 268 yards, including a 39-yard score to Charles Clay, who broke two tackles on the play. Miami managed 104 yards rushing behind a makeshift line.
The victory came amid a harassment scandal that raised questions regarding the team's locker room culture. An NFL special investigator will question players this week about the relationship between offensive tackle Jonathan Martin and guard Richie Incognito.
"There's a lot going on, but we're not focused on that," Tannehill said. "We're focused on football."
The Dolphins (5-5) won for only the second time in the past seven games. They're still in contention for an AFC wild-card berth, despite a dreadful defeat last Monday at Tampa Bay and the distractions of the harassment case.
"We're fighting through this," tackle Tyson Clabo said. "Someone's got to get that last wild-card spot. Why not us?"
The Chargers (4-6), who were plagued by penalties and missed tackles, lost their third game in a row.
"We made too many mistakes from start to finish," coach Mike McCoy said. "We hurt ourselves way too much."
Trailing by four points, San Diego started from its own 17 with 1:54 left and drove to the Miami 25. On the final play, a harried Rivers lofted a pass toward Vincent Brown in the end zone, but the 5-foot-10 Grimes leaped to slap the ball away.
Rivers threw for 298 yards and Ryan Mathews ran for 127, including a career-best, 51-yard dash to set up a field goal. But the Chargers had 10 penalties for 76 yards, including two infractions that cost them 11 points in the first half.
"Ten penalties, that's a lot," Rivers said. "We're not playing well enough to overcome those things."
Miami played at home for the first time since the scandal broke. The stands were less than two-thirds full, and an airplane banner reflected the mood by calling for the firing of general manager Jeff Ireland, who has long been in disfavor with fans.
Because center Mike Pouncey missed the game with an illness, the Dolphins had three backups starting on the offensive line. Martin missed his third consecutive game while undergoing treatment for emotional issues, and the suspended Incognito sat out his second game.
Working behind the patchwork line, Tannehill was sacked four times, increasing his NFL-high season total to 41. But Miami averaged 5.5 yards per rush to limit the Chargers' time of possession.
As usual, the Dolphins went with pass plays two-thirds of the time. On the game's opening drive, they marched 76 yards -- with all but 2 coming through the air -- for a field goal.
Penalties repeatedly hurt the Chargers. Corey Liuget was flagged for roughing the passer to negate a teammate's fumble recovery at the San Diego 1, and two plays later the Dolphins scored a touchdown for a 10-7 lead.
Liuget said he didn't see Tannehill get rid of the ball.
"It was a costly penalty for us," Liuget said. "I wish I could get that one back. It's not a great feeling at all."
A scrambling Rivers hit Antonio Gates for a 5-yard touchdown with a minute left in the first half, but the quarterback was flagged for throwing past the line of scrimmage, and the Chargers settled for a field goal that made it 10-all at halftime.
A drive in the second half stalled after receiver Keenan Allen was flagged 15 yards for taunting, and the Chargers defense was penalized four times for offsides.
San Diego's Derek Cox dropped a potential pick-six in the first quarter, and on the next play Johnny Patrick intercepted Tannehill at midfield. The Chargers scored four plays later for a 7-3 lead.
Clay put Miami ahead to stay in the third quarter when he caught a short pass and ran over defenders Marcus Gilchrist and Donald Butler en route to the end zone, making it 17-10.