Dallas Cowboys survive late threat to beat Detroit Lions