Jared Goff threw for 303 yards with three touchdowns and Jahmyr Gibbs had 163 total yards and a touchdown to lead the Detroit Lions to a 40-34 win against the San Francisco 49ers.