Tony Romo suffered a fractured rib in the first half and missed some time in the third quarter, but engineered the game-tying drive late in the fourth and hit Jesse Holley with a 77-yard pass to set up the game-deciding field goal.
Romo threw for 345 yards and two scores on 20-of-33 pass attempts in the win for Dallas (1-1).
"That was a great win for a lot of different reasons," said Cowboys head coach Jason Garrett. "We talk all the time that it takes everybody (to win) and we certainly found that out today."
Trailing by three with a little over four minutes left in the game, Dallas started a drive at its own 26-yard line. Romo completed back-to-back passes to Holley, placing the ball at the Dallas 45.
An Austin seven-yard catch gave the Cowboys a first down after the two-minute warning. Another seven-yard grab by Austin and a one-yard run by Tashard Choice gave Dallas a third-and-two at the 28-yard line. The Cowboys gave a toss to Austin, who was stopped short of the first down and fumbled, but Dallas recovered at the 30.
Bailey's 48-yard field goal as time expired tied the game and sent it into overtime.
The 49ers won the toss and got the ball to begin the extra period. Smith started the drive with a 12-yard completion to Ted Ginn Jr. But after a seven- yard run by Frank Gore, Smith was sacked for an eight-yard loss. San Francisco couldn't convert the third down and was forced to punt.
On Dallas' first play of their drive, Romo floated a pass down the middle to Holley for a 77-yard gain. Holley was taken down at the one-yard line,
Bailey stepped up and split the uprights on a 19-yard field goal to give the Cowboys their first win of the year.
"I'm proud of our guys. I thought they played their hearts out. I thought they played well enough to win. But we didn't win," said 49ers head coach Jim Harbaugh. "I take my hat off to the Cowboys. They dug themselves out of a hole and came back to win it."
Romo led a 14-play, 7 1/2-minute drive to start the game, leading the Cowboys down to the San Francisco three-yard line, but the drive stalled there and Bailey missed a 21-yard field goal wide right.
Each team then traded punts before the 49ers started a drive at their own 32 with 3:34 left in the first quarter. San Francisco converted all three third- down attempts on the drive and a pass interference penalty on Bradie James in the end zone put the ball on the one-yard line.
Gore rumbled in for the score to put the 49ers ahead early in the second quarter.
Dallas was forced into a three-and-out on its next possession and Ginn returned the ensuing punt 20 yards to the Cowboys' 48-yard line.
Smith made completions of 12 and 10 yards to Josh Morgan before hitting Williams on the left-side of the end zone for a 12-yard score. Williams made the grab over a defender and kept his feet inside the sideline for his first career touchdown.
After the teams traded punts again, the Cowboys took over with a little over three minutes to go in the half. Romo's pass fell incomplete on a third-and- nine, but a San Francisco offsides penalty gave Dallas a second chance.
On the next play, Romo hit Austin for a 53-yard score to make it a 14-7 game at the half.
Romo did not return for the second half as he received a fractured rib on a hit during a pass attempt in the first half, and Jon Kitna took over the offense for the start of the third quarter.
Kitna hit Witten for 12 and nine-yard gains on his first drive of the third, but overthrew Witten in the end zone, resulting in a Donte Whitner interception.
Three plays later, though, Smith was picked off by Alan Ball at his own 33 and Ball ran down to the 49ers' 18-yard line. Kitna found Austin for a five-yard TD on the drive to tie the game.
On Dallas's next possession, Kitna tossed his second interception of the quarter, and on the next play Smith dropped a pass into the hands of Walker for a 29-yard score with under a minute to go in the third.
Romo took the field for the Cowboys' next possession, but was held to a three- and-out. San Francisco then took over at its own 48 and a Smith 12-yard scramble set up David Akers' 55-yard field goal, putting the 49ers ahead 24-14 with 11:12 to go in the game.
Dallas was flagged for unsportsmanlike conduct on the kick, but Harbaugh curiously opted to take the points instead of extending the drive.
Romo led the Cowboys 80 yards down the field, going 5-of-7 through the air, including a fourth-down conversion and a 25-yard touchdown pass to Austin to make it a three-point game.
Cowboys wide receiver Dez Bryant sat out with a bruised thigh...The 49ers have a 14-11-1 lead in the overall regular-season series between these teams, but have lost their last three games against the Cowboys...Gore carried the ball 20 times for 47 yards and a score...Felix Jones led the Cowboys with 25 yards on nine carries...Dallas went 6-for-14 on third downs conversions and converted its lone fourth-down attempt...San Francisco went 8-for-16 on third downs.