ARLINGTON, Texas (AP) — Versatile receiver Deebo Samuel ran 26 yards for a touchdown the play after an interception by Dak Prescott, and the San Francisco 49ers held on for a 23-17 wild-card victory over the Dallas Cowboys on Sunday.

The Cowboys had a final chance with 32 seconds remaining and were at the San Francisco 41 with 14 seconds to go when Prescott took off up the middle intending to slide and spike the ball for a final play.

But Dallas didn’t get the snap off from the 24 until after the clock hit 0:00. After a brief delay, referee Alex Kemp announced the game was over.

The 49ers overcame an interception by Jimmy Garoppolo when they led by 13 in the fourth quarter. Prescott ran for a touchdown to get within a score, and had a chance to drive Dallas to a go-ahead score. But the 49ers got a stop at midfield when Prescott’s desperation fourth-down pass was just out of the receiver Cedrick Wilson’s reach.

After a 14th penalty from the NFL’s most-penalized team in the regular season that helped San Francisco run out most of the clock — and the frantic final seconds as Dallas tried for the win — the 49ers (11-7) clinched their first playoff victory at the Cowboys in a storied postseason rivalry.

Now they head to Tampa Bay for a divisional game, looking for another trip to the NFC championship game.

The wait for Dallas (12-6) to get that far in the playoffs will reach at least 27 years after another first-game flameout in the postseason for Prescott, the second in three trips for the star quarterback. It was his first playoff game since signing a $40-million-a-year contract in the offseason.

The 49ers were in control in the fourth quarter, but not leaning on the running game they figured could carry them to a win when Garoppolo threw an interception to Anthony Brown that set up Prescott’s 7-yard scoring run.

Garoppolo’s mistake wasn’t long after Prescott was picked off at the Dallas 26 by K’Waun Williams and Samuel ran untouched on a cutback up the middle to the end zone on the next play for a 23-7 lead.

San Francisco lost star pass rusher Nick Bosa to a concussion just before halftime when he was crunched in the head and neck area by teammate D.J. Jones. But the 49ers kept enough pressure on Prescott, finishing with five sacks while holding the NFL’s No. 1 offense to 307 yards.

San Francisco scored on its first four possessions, but three times settled for field goals from Robbie Gould to help keep the Cowboys close.

Garoppolo gave Dallas life later with an overthrow that Brown caught and returned to the San Francisco 28. Prescott scored five plays later.

The Cowboys had all three timeouts after Prescott’s desperate pass to Wilson fell incomplete.

The 49ers got a first down on the second holding penalty by a Dallas defensive lineman on a running play, and Samuel got all but a few inches needed for a first on a third-and-11 run with a minute remaining.