Trent Richardson scored a 1-yard touchdown on his first carry in his Colts debut after being acquired on Wednesday from the Browns. He was drafted two spots behind top pick Luck at No. 3 last year.
Ahmad Bradshaw added a 1-yard TD run in the final minutes, and Adam Vinatieri kicked a pair of field goals before missing a 51-yarder early in the fourth.
It was Colin Kaepernick's first home loss at Candlestick Park as a starter.
There were few bright spots for Kaepernick as San Francisco struggled to establish a passing game with tight end Vernon Davis sidelined by a hamstring injury.