49ers outlast Cardinals with big, timely plays