MIAMI GARDENS, Fla. — Colin Kaepernick drew boos at the start of the game, and throughout much of the action. By the end, he had Dolphins fans holding their breath.

Ndamukong Suh tackled Kaepernick 2 yards short of the goal line as time ran out, and the Dolphins handed the San Francisco 49ers a franchise-record 10th consecutive loss by winning 31-24 Sunday.

Kaepernick, who has drawn mixed reactions for kneeling during the national anthem all season, was jeered loudly, especially upon entering the field, after he defended Cuban dictator Fidel Castro earlier in the week. He threw for 296 yards, ran for 113 and rallied the 49ers after they trailed 31-14 midway through the fourth quarter.

With the margin down to seven, Kaepernick moved the 49ers from their 38 to the 6 in the final 1:44, converting a fourth-and-11 along the way. But he threw incomplete on first down, and then was tackled from behind by the 305-pound Suh while trying to elude linebacker Kiko Alonso on the final play.

“I just played what I saw,” Suh said. “I had a one-on-one against a guard. I needed to beat him and then get to the quarterback. It’s not the cleanest or best way to get it done, but we got it done.”

The dramatic stop was cathartic for Dolphins fans — many of whom are Cuban-Americans — who were angered after Kaepernick defended a shirt he wore in August depicting Castro. Miami media grilled Kaepernick on Wednesday on a conference call, in which he defended the Cuban leader, who died Friday, arguing Cuba focused more on education than imprisoning its people. A column in the Miami Herald called him a “fraud.”

Kaepernick ignored the hostility, but wasn’t able to get the 49ers over the top. He said the final play was called as a pass, and he faked a throw before taking off.

“I thought we had a seam to get in there and didn’t make it,” he said.

Kaepernick passed for three TDs, but the 49ers (1-10) still haven’t won since the season opener.

Instead, the Dolphins (7-4), behind three scores and 285 yards from Ryan Tannehill, extended their winning streak to six games, their longest since 2005.

“It’s great to see our guys have fun at the end of the day,” first-year coach Adam Gase said. “They understand a win in this league is hard to come by.”

Tannehill went 20-for-30, ran for 34 yards and had no turnovers. He threw scoring passes of 16 yards to Dion Sims, 43 yards to Kenny Stills and 15 yards to rookie Leonte Carroo.

Kaepernick tried to keep up. He went 29-for-46 and also hurt the Dolphins with his legs, but fell to 0-6 as a starter this year.

Miami won even though Jay Ajayi had trouble finding running room behind an offensive line missing three starters. He gained 45 yards in 18 carries against a 49ers defense ranked last in the league against the run.

“They decided they were going to make us throw to win,” Tannehill said. “So that’s what we did.”

Tannehill put the Dolphins ahead to stay with his 100th touchdown pass in his fifth NFL season, and Carroo’s first career touchdown made it 31-14 with 11:31 left.

It was a different approach for the Dolphins, who had rallied in fourth quarter in their four previous games.

This time the opponents mounted a comeback. Torrey Smith made a one-handed catch for a 1-yard touchdown to help the 49ers close to 31-24 with less than three minutes left, and they quickly forced a punt to set up the down-to-the-wire finish.