It was that kind of crazy, back-and-forth game at the Oakland-Alameda County Coliseum, and it has been that kind of season for the Cowboys.
The Raiders quickly drove to the Dallas 8-yard line, taking advantage of a 55-yard pass-interference penalty. Then on third-and-3 from the 8, Raiders quarterback Derek Carr fumbled while diving for the right pylon and taking a hit from Cowboys safety Jeff Heath at the end of a scramble. The ball went into the end zone and out for a touchback.
Dallas took over with 31 seconds left and ran out the clock for a 20-17 victory.
"There was a lot of emotion in that game, and it happened fast," Cowboys tight end Jason Witten said. "We know where we're at. Our season is on the line as far as going to the playoffs. It's good to see us find a way to get the result that we did.
"Unbelievable play by Jeff Heath. There's something about this football team. Good to get lucky and see the football gods help you out a bit. I've certainly been on the other end of it over the course of my years."
The Cowboys (8-6) improved their slim hopes for an NFC wild-card playoff berth. They moved into a tie with the Detroit Lions and Seattle Seahawks, a half-game behind the Atlanta Falcons (8-5) for the conference's second wild-card spot.
"We know where we are," Cowboys quarterback Dak Prescott said. "Our backs are against the wall. We got to win. That's what this team's about. We're excited."
Despite the loss, the Raiders (6-8) are still barely alive in AFC wild-card race.
"I left it all out there," Carr said of his diving attempt to score. "I'm just trying to win for my teammates. No excuse. I have to hold onto the ball. You know, the fight our team played with today, that was familiar. That looked like us."
One play before Carr's fumble, Heath made an acrobatic breakup of Carr's pass to wide receiver Michael Crabtree in the end zone.
Then on the decisive play, Heath helped knock the ball out of Carr's left hand a foot or so before the goal line.
"These games are won and lost on these kinds of drives," Heath said. "The key in a drive like that is to just stay calm, use your technique and see what happens. But you try not to be frantic."
Prescott completed 18 of 27 passes for 212 yards and no touchdowns with two interceptions. He carried six times for 32 yards and one score.
Carr completed 21 of 38 passes for 171 yards and two scores with no interceptions. Oakland cornerback Sean Smith had two interceptions.
"It was a gritty effort back and forth," Raiders coach Jack Del Rio said. "Really, really believed that we were going to pull it out and I'd be sitting up here with a big smile. But I'm proud of the guys, the way they fought."
On the winning drive, the Cowboys faced fourth-and-1 at their 39 with 5:09 left. Prescott got the first down by less than an inch on a 1-yard sneak.
Three plays later from the Oakland 45, Prescott hit Dez Bryant for 40 yards down the right sideline, giving the Cowboys first-and-goal from the 5, setting up Bailey's field goal.
The Raiders had 14 penalties for 105 yards, two of them nullifying touchdowns.
Cordarrelle Patterson's 100-yard kickoff return for an Oakland touchdown to open the second half was wiped away because of a holding call on Xavier Woodson-Luster. However, the Raiders drove 90 yards on 11 plays and cut Dallas' lead to 10-7 on Carr's 2-yard touchdown pass to Crabtree with 8:03 left in the third quarter.
On Dallas' ensuing drive, Smith made a diving interception along the sideline, got up and raced 22 yards for an apparent touchdown. After a video review, it was determined that Cowboys wide receiver Cole Beasley touched Smith while he was on the ground, nullifying the touchdown.
The Raiders settled for Giorgio Tavecchio's 39-yard field goal, making it 10-10 with 6:14 left in the third quarter.
Dallas moved back ahead 17-10 on Prescott's 5-yard touchdown run with 45 seconds left in the third quarter, capping a wild 11-play, 75-yard drive.
Punter Chris Jones ignited the scoring drive with a 24-yard run up the middle to the Dallas 48 on a fake punt.
Oakland pulled even at 17 on Carr's 2-yard touchdown pass to Crabtree with 10:35 left, capping a 10-play, 53-yard drive.
The Cowboys' opening drive of the game ended when Smith intercepted Prescott's pass in Oakland territory.
Dallas took a 3-0 lead on its next drive when Bailey kicked a 45-yard field goal with 4:56 left in the first quarter.
The Cowboys extended their lead to 10-0 on Rod Smith's 1-yard touchdown blast with 14:04 remaining in the first half.
The Raiders drove to the Cowboys' 11 late in the first half but came up empty. Carr's 11-yard touchdown pass to Jared Cook was nullified by an offensive pass-interference call on the tight end. Tavecchio missed a 39-yard field goal try on the final play of the half.
NOTES: Raiders RT Donald Penn left the game in the first quarter with a foot injury and did not return. ... Cowboys RB Ezekiel Elliott served the sixth and final game of his suspension for violating the NFL's personal-conduct policy. ... Raiders WR Amari Cooper (ankle) was inactive for the second time in the past three weeks. ... Cowboys starting CB Orlando Scandrick (back) and DT David Irving (concussion) were inactive. ... Raiders starting DE Mario Edwards (ankle) was inactive for the first time this season. ... Cowboys LT Tyron Smith sustained a knee injury in the third quarter and did not return.