South Carolina guard Allisha Gray, center, grabs a rebound against Florida State guard Brittany Brown during the second half of a regional final game of the women's NCAA college basketball tournament, Monday, March 27, 2017, in Stockton, Calif. South Carolina won 71-64. (AP Photo/Rich Pedroncelli) (Rich Pedroncelli/AP)

The South Carolina women’s basketball team rallied from a double-digit deficit in the first half, then survived a late rally from Stanford to claim a 62-53 victory in the NCAA tournament’s national semifinals Friday night at American Airlines Center.

Behind junior guard Allisha Gray’s game-high 18 points and junior forward A’ja Wilson’s 13 points and game-high 19 rebounds, the Gamecocks (32-4) advanced to the first national championship game in program history. South Carolina, the No. 1 seed out of the Stockton Region, will face Mississippi State, which stunned Connecticut in overtime, in Sunday’s final.

“Just making history at your school is something special,” said Wilson, the two-time SEC player of the year.

The Gamecocks closed with nine of the game’s final 12 points, including four consecutive free throws from freshman guard Tyasha Harris to complete the scoring in a defensive struggle. Both teams shot 37 percent, and neither side shot above 29 percent from three-point range.

Making its second appearance in the Final Four, South Carolina beat tradition-rich Stanford for the first time in school history. The Gamecocks entered having lost all five previous matchups to the two-time national champions, who had earned their 13th berth in the Final Four and seventh over the past 10 seasons, all under Hall of Fame Coach Tara VanDerveer.

A 19-4 surge to open the third quarter pushed the Gamecocks ahead 39-33 with a 1:42 to play. During one stretch, South Carolina scored 13 consecutive points, with junior guard Bianca Cuevas-Moore’s three-pointer with 3:28 left providing to the Gamecocks with the lead for good. It was their first lead since the start of the second quarter.

Stanford went six minutes without scoring in the third quarter until junior guard Brittany McPhee’s jumper with 46 seconds to go trimmed the deficit to 39-35. The No. 2 seed from the Lexington Region got within two on sophomore forward Alanna Smith’s jumper, but South Carolina went into the fourth quarter ahead 41-37 on freshman forward Mikiah Herbert Harrigan’s putback.

“The second half I thought we imposed our will from a defensive standpoint,” South Carolina Coach Dawn Staley said. “Our team has incredible focus on the end result. Good teams can bounce back from adverse situations in the game.”

The Cardinal took a 29-20 lead into halftime behind a run triggered when Marta Sniezek entered the game early in the first quarter. The McLean native and 2015 first-team All-Met from National Cathedral scored or assisted on 15 consecutive points as part of 17-5 burst, providing Stanford with a 21-14 lead that grew to as many as 10 with 1:33 left in the first half.

Stanford was able to keep the Gamecocks at bay in the first half despite temporarily losing Karlie Samuelson, the Division I leader in three-point field goal percentage, to a turned ankle with 4:48 left in the second quarter. The senior was tripped up as she tried to get around a screen. She remained down on the court holding her right leg in considerable discomfort while being examined by the team trainer.

Eventually, teammates carried Samuelson to the bench. She soon went to the locker room for additional observation, emerged for second-half warmups and reentered late in the third quarter but did not take a shot the rest of the way.

“We just really struggled without our glue, Karlie,” VanDerveer said. “We were really out of sync.”