SANTA CLARA, Calif. — As Sunday’s wild-card game against the Dallas Cowboys appeared to be slipping away in the closing moments, a quiet sense of calm remained on the San Francisco 49ers‘ sideline.

On four possessions since receiver Deebo Samuel‘s 26-yard touchdown run, the Niners’ offense went punt, interception, punt, punt and a 16-point lead had shrunk to six. Yet nobody on San Francisco’s offense seemed panicked that advancing past the Cowboys and into the NFL’s divisional playoff round seemed in doubt.

The reason for the relative sideline serenity? A defense that was once again proving it could more than hold its own against the NFL’s highest-scoring offense.

“Those guys really did their part,” quarterback Jimmy Garoppolo said. “That’s why I felt like we were so in control of the game. That’s a good offense they were going against, and they kept them in check the whole game. It was really impressive.”

What 49ers defensive coordinator DeMeco Ryans and his group did against the Cowboys during a 23-17 victory was, perhaps, their finest performance of the season given the quality of the opponent and the significant stakes of the matchup. Ryans’ defense held Dallas to 17 points, 307 yards and 4.4 yards per play, well removed from season averages of 31.2, 407 and 6.0, respectively. The 49ers did it despite defensive end Nick Bosa (concussion) missing the second half and linebacker Fred Warner departing early in the fourth quarter because of an ankle injury.

The 49ers’ defense proved it is, in fact, a dominant group capable of serving as the centerpiece of a legitimate contender for the NFC championship.

“The defense has been playing pretty much lights out for the whole year,” left tackle Trent Williams said. “I don’t think we would be where we are today if we had just an above-average defense. I think our defense has to be great for us to be good and be great.”

After the offseason departure of coordinator Robert Saleh to the New York Jets as head coach, there was always going to be a learning curve for Ryans, a first-time defensive coordinator. There were some early bumps, including a Week 3 loss to Green Bay in which the Packers needed just 37 seconds to get in position for a field goal and a 30-28 last-second victory.

Ryans has settled in since, discovering a better rhythm for disguising coverages and mixing calls. San Francisco finished third in the NFL in yards per game allowed (310), sixth in yards per play (5.11), sixth in passing yards allowed per game (206.5) and seventh in rushing yards allowed per game (103.5).

They did it by playing a lot of zone coverage and leaning on the front four to generate pressure on the quarterback. San Francisco played zone on 66.1% of snaps (third most in the NFL) and held opposing quarterbacks to a QBR of 41.5 (14th).

Like Saleh before him, Ryans developed a better sense of when to blitz, often choosing to lean on his front four to do most of the pass-rushing damage. The Niners finished with 48 sacks on the season, tied for fifth most in the league — the same number they had in 2019 when that defensive line was considered one of the most dangerous in the league. San Francisco finished third in sacks per drop back (7.7%), first in forced fumbles (22) and fifth in pass rush win rate (45.9%).

Ryans has a knack for dialing up blitzes at the right time and did so against the Cowboys, sending the house at quarterback Dak Prescott to force a deep fourth-down incompletion with less than 2 minutes remaining.

“DeMeco has been unbelievable all year,” coach Kyle Shanahan said. “I thought DeMeco did a perfect job today of mixing it up and then calling that zero [blitz] there at the end on fourth down.”

The 49ers played zone on 82% of snaps against Prescott, the highest rate he has faced in his career. He finished with a QBR of 23 and averaged 4.5 yards per drop back, both of which were his second-lowest numbers of the season, according to NFL Next Gen Stats.

What’s more, the Niners had five sacks and 22 pressures in addition to holding Cowboys running back Ezekiel Elliott to 31 yards on 12 rushes. San Francisco hasn’t allowed a 100-yard rusher since Bears quarterback Justin Fields did so on Halloween.

The credit for that goes to a subtle but effective personnel move Ryans made when he asked lineman Arik Armstead to play defensive tackle full time following Javon Kinlaw‘s season-ending knee surgery.

“He’s the most important piece on this team to me,” defensive tackle D.J. Jones said. “I think Arik Armstead is a force. He can play outside, inside … he’s a Swiss Army knife.”

Things won’t get any easier this week with Aaron Rodgers and the Packers next on the schedule (8:15 p.m. ET Saturday, Fox). But you’d be hard-pressed to find a defense playing with more confidence than the Niners.

“We went in there and did what we needed to do,” free safety Jimmie Ward said after beating the Cowboys. “Stop the run and force them to be one-dimensional and see if Prescott could win the game for them.”

Where Prescott failed, the 49ers’ defense succeeded.