With just under two minutes left in Saturday’s matchup against Michigan State, No. 8 Maryland women’s basketball led by nine points after Diamond Miller knocked down a free throw as it looked to ease its way to a fourth consecutive victory.

But turnovers on three straight possessions led to back-to-back three-pointers from the Spartans to cut the Terps’ lead to just three.

DeeDee Hagemann followed with a free throw to cut the deficit to two, and the hosts just needed a three to tie the game after Abby Meyers made only one of her two shots from the charity stripe.

Michigan State associate head coach Dean Lockwood, who manned the bench as Suzy Merchant continues to recover from a car accident, drew up a final play, but Hagemann missed the team’s final three-point attempt with just three seconds remaining.

“They played hard, they were strong, they were resilient,” Miller said. “They did not stop. They didn’t care what their score was, they played the same way the whole time.”

Despite being outscored 20-12 in the fourth quarter, the Terps (22-5, 13-3 Big Ten) narrowly avoided an upset with a 66-61 win over the Spartans (13-13, 5-10) at the Breslin Center. Maryland is now 10-2 on the road this season.

“Michigan State was one possession away from being able to take this game from us,” Maryland coach Brenda Frese said, “but I liked the fact that we were able to hang on and be able to get a tough road win.”

Maryland didn’t score a field goal for almost seven minutes of the fourth quarter as the Spartans cut the Terps’ lead to single digits. But Maryland got to the line and held Michigan State scoreless for nearly three minutes to maintain its advantage.

[Maryland women’s basketball didn’t make a three-pointer against Illinois. It didn’t matter.]

The Spartans rallied and almost took advantage of the Terps’ turnovers en route to a comeback victory late, but Maryland withstood the late Michigan State run to notch its fourth straight win.

Many on Michigan State’s bench wore “Michigan Strong” shirts and Maryland players wore green and orange ribbons on their jerseys during the game — green in support of the Spartans community and orange for victims of gun violence.

“Our thoughts are with the entire Michigan State community. What happened this week was unimaginable. Everyone here is thinking of them,” Frese said before the game.

A 13-3 Maryland run in the third, led by Miller, who has 60 points in her last two games, helped the Terps to a quarter in which they outscored the Spartans by 12 points and shot 50 percent from the field compared to Michigan States’ 26.3 percent.

“Fortunately, we’ve been having really good third quarters,” Frese said. “I thought the difference was we were able to get back to playing [Sellers] and playing our bench. We were in foul trouble the entire game, so just getting your regular lineup back out on the floor.”

Coming into Saturday’s match at Michigan State, Miller was averaging 7.4 free-throw tries per game. But against the Spartans, Maryland’s scoring leader went to the line a career-high 19 times and made 11 of her attempts.

“It’s just what I do,” Miller said of her ability to get to the free-throw line. “I draw defenses, and I’m able to maneuver, so people foul me. It’s just part of my game — getting to the foul line.”

[Third quarter domination lifts No. 8 Maryland women’s basketball past Illinois, 82-71]

Miller finished with a game-high 29 points, and the Terps had ample opportunities to get to the line throughout the game, shooting a joint season-high 37 free throws.

The Terps also struggled with discipline early; Shyanne Sellers and Lavender Briggs picked up two fouls in the first quarter, limiting the pair’s minutes. The two combined for just nine minutes in the opening quarter.

“They were able to get us into really early foul trouble, which kind of threw us out of rhythm,” Frese said.

Maryland particularly missed Sellers on offense as the Ohio native is the team’s second-leading scorer behind Miller. Sellers finished with a season-low two points after fouling out in the game’s final minutes. She has logged less than 10 points just four other times this year.

A game after going 0-for-17 from three against Illinois, Maryland again struggled from behind the arc to kick off the contest. The team started 0-for-7 from three before Faith Masonius broke a nearly an hour-long streak with a three-pointer at the 2:25 mark of the second.

The Terps finished the affair shooting 28.6 percent from three, with Meyers (14 points, six rebounds) notching half of the team’s four makes.

Julia Ayrault led Michigan State with 15 points and Matilda Ekh finished with 11 points, all of which came in the second half. Maryland held Kamaria McDaniel, the Spartans’ leading scorer, to just one point.

Saturday’s victory guarantees the Terps a top-four seed in the conference tournament, which means a double-bye into the quarterfinals. Maryland hosts No. 7 Iowa Tuesday before traveling to face No. 13 Ohio State Friday in its regular season finale.