Bailey was true on a score-tying 48-yarder as regulation time expired and then nailed a 19-yard attempt in overtime for Dallas (1-1).
Tony Romo racked up 345 yards and two scores on 20-of-33 pass attempts, overcoming a fractured rib suffered in the first half.
Despite the injury, he engineered the score-tying drive late in the fourth and then hooked up with Jesse Holley on a 77-yard pass to set up the game-winning kick.
San Francisco (1-1) was led by Alex Smith, who completed 16-of-24 passes for 179 yards, two touchdowns and an interception.
Jordana Brewster on Paul Walker: 'He was an enormous presence in my life'
Gal Gadot cast as Wonder Woman for 'Batman vs. Superman'