The 49ers’ defense faced their biggest challenge of the season. And with the team in need of a stop, the coaching staff decided it was time to get cornerback Emmanuel Moseley on the field in place of Ahkello Witherspoon.

“Just a gut feeling,” 49ers coach Kyle Shanahan said about the decision to go with Moseley with the NFC West title on the line.

Witherspoon started and played 59 snaps at right cornerback in the 49ers’ critical Sunday night game against the Seattle Seahawks. Moseley made a play in the final minute to help the 49ers preserve a 26-21 victory, clinching home-field advantage in the NFC playoffs.

Seattle quarterback Russell Wilson completely ignored Richard Sherman’s side of the field the entire game and went after Witherspoon, who was coming off a rough game against the Los Angeles Rams in Week 16.

Shanahan and defensive coordinator Robert Saleh expressed confidence last week in Witherspoon’s ability to turn it around. But it got to the point late in the second half that the 49ers felt the best shot they had to win the game was with Moseley on the field.

Witherspoon gave up six receptions (on eight targets) for 71 yards, including touchdown receptions to Tyler Lockett (14 yards) and D.K. Metcalf (14 yards). Wilson’s scoring pass to Metcalf cut the 49ers’ lead to 26-21 with 3:36 remaining.

That’s when the 49ers turned to Moseley.

“Ahkello has played some good ball this year, so has Moseley,” Shanahan said. “Just at the end there when you know I don’t get to see it all, but want to give E-Man a chance. You know they were coming at him a couple times and I did not think Ahkello played a bad game by any means.”

Wilson went after Moseley on the final drive, completing two of the five passes thrown his way for 34 yards. Moseley made one of the best defensive plays of the game with a diving pass-breakup to prevent a potential 12-yard touchdown pass to Metcalf with 51 seconds remaining in the game.

The 49ers have some time to figure out what they want to do at cornerback, but it appears likely Moseley will get the call when the club opens the playoffs with an NFC divisional-round game at Levi’s Stadium on Saturday, Jan. 11.

Shanahan said immediately following the game he would watch the game film on the trip back to the Bay Area to help him form his opinion of Witherspoon’s overall performance.

“I’ll see it on the plane but I thought they just got him in a couple opportunities and came up short in both of those,” Shanahan said. “Wanted to throw another guy in there and see how it went, and I’ll see on the plane when I watch the film.

“But nothing against Ahkello going forward, but we put two guys out there who believe in. We switched it up there at the end.”

[RELATED: 49ers report card: Grades on offense, defense in 26-21 win over Seahawks]

Moseley started nine games, beginning Week 5 against Green Bay after Witherspoon missed two months due to a foot sprain.

Here is a look at how much everyone on the 49ers played Sunday on offense, defense, and special teams:

Offense

Total offensive snaps: 50

Quarterback – Jimmy Garoppolo 50

Running back – Kyle Juszczyk 34, Raheem Mostert 27, Tevin Coleman 15, Matt Breida 8

Wide receiver – Emmanuel Sanders 46, Deebo Samuel 39, Kendrick Bourne 10, Richie James 4

Tight end – George Kittle 47, Levine Toilolo 15, Ross Dwelley 5

Offensive line – Daniel Brunskill 50, Mike McGlinchey 50, Laken Tomlinson 50, Ben Garland 50, Joe Staley 50

Did not play – QB Nick Mullens, WR Dante Pettis, OL Mike Person

Defense

Total defensive snaps: 75

Defensive line – DeForest Buckner 65, Nick Bosa 64, Arik Armstead 63, Sheldon Day 30, Solomon Thomas 30, Anthony Zettel 29, Kevin Givens 10, Kentavius Street 8

Linebacker – Fred Warner 75, Dre Greenlaw 74, Azeez Al-Shaair 18, Mark Nzeocha 1

Defensive back – Marcell Harris 75, Richard Sherman 74, Jimmie Ward 73, Ahkello Witherspoon 59, K’Waun Williams 56, Emmanuel Moseley 15, Tarvarius Moore 6

Special teams

Total special teams plays: 22

Moore 18, Elijah Lee 17, Nzeocha 17, Moseley 16, James 13, Mitch Wishnowsky 12, Antone Exum 11, Ward 10, Mostert 9, Breida 9, Dwelley 8, Buckner 8, Armstead 8, Al-Shaair 8, D.J. Reed 7, Kyle Nelson 6, Harris 6, Toilolo 5, Bourne 5, Thomas 5, Robbie Gould 4, Justin Skule 4, Staley 4, Garland 4, Brunskill 4, McGlinchey 4, Tomlinson 4, Juszczyk 3, Day 3, Coleman 2, Warner 2, Greenlaw 2, Kittle 1, Bosa 1, Williams 1, Zettel 1

Not active

QB C.J. Beathard

S Jaquiski Tartt (ribs)

RB Jeff Wilson

CB Dontae Johnson

TE Daniel Helm

DE Dee Ford (hamstring)

WR Jordan Matthews