Junior midfielder John Stertzer compensated for a missed a penalty kick in the first overtime by scoring on a header in the second sudden-death extra period as the top-ranked Maryland soccer team survived a scare by Maryland-Baltimore County, 4-3, on Tuesday night in Catonsville, Md.

Senior forward Casey Townsend recorded a hat trick for the Terrapins (6-0-0), who are No. 1 in both the coaches’ poll and the Soccer America rankings.

Maryland, which will host North Carolina State on Friday, relinquished a 3-1 lead late in the second half against the Retrievers (2-1-2). In the 20-minute overtime, Stertzer had his penalty saved in the 100th minute but later headed in Taylor Kemp’s free kick in the 104th.

Townsend opened the scoring in the 46th, and after UMBC drew even, added goals in the 57th and 71st minutes to increase his season total to eight. Seth Rothe brought the Retrievers back, scoring 71 seconds apart in the 83rd and 84th minutes.

Maryland avoided the upset, but ACC rival Virginia did not. Liberty defeated the 12th-ranked Cavaliers (4-2-0) for the first time in 20 meetings, 2-0, in Charlottesville.