San Francisco 49ers earned a playoff berth by withstanding a stunning comeback by New England from a 28-point deficit to beat the Patriots 41-34 on Sunday night in the rain.