Cotter relieved after late victory