49ers secure crucial victory