SANTA CLARA >> Take a breath, 49ers fans. You need one.

Chaos hasn’t even begun to describe this season so far. This team has been downright exhausting for months. And Sunday’s first-half-of-the-season finale against the Cowboys proved to be no different.

Following their worst performance of the season last week against the Chiefs, the Niners carried that form into the first half Sunday. Penalties wiped big plays — including a 66-yard touchdown — off the board, the defense couldn’t seem to get off the field on third down, and Niners quarterback Brock Purdy was scattershot with his throws. San Francisco trailed 10-6 after two quarters. It was a downright ugly 30 minutes.

Yet the Niners were playing down to an unquestionably inferior team at home in a must-win game. You don’t get to lose back-to-back games twice in the first half of a campaign and still consider yourself a Super Bowl contender, and here the Niners were going for that status.

If ever there was a time for head coach Kyle Shanahan to deliver a rah-rah speech — to light a fire under his team — Sunday’s intermission was the time.That didn’t happen.

“That’s more for movies,” Shanahan said. “Sometimes I have to go to the bathroom.”

The Niners flushed away the first half and handled Dallas in the second half, winning 30-24, even without a Shanahan rallying cry.

Yes, of course, there were some harrowing moments late on Sunday. It’s the 49ers after all.

But in the end, the Niners played one strong quarter of football — the third — and moved to 4-4 on the year.

Stop me if you’ve heard this before, but everything the 49ers want to achieve is still in front of them. They’re tied for the lead in the NFC West in a conference that remains wide open. They haven’t impressed this season, but they’ve hardly disqualified themselves, either.

And facing the ultimate gut check on Sunday, this team responded.

Maybe it was a blip. The Cowboys are an even bigger mess than the Niners.

Or perhaps the Niners, facing a truly sobering moment, finally shook off that last bit of a Super Bowl hangover.

If you’re looking for silver linings, relief (though not the kind Shanahan might have received at halftime), or optimism amid a season that’s felt, at times, cursed, that 21-0 third quarter was for you.

“We felt like the superior team, and we just needed to execute a little better,” Nick Bosa said of the halftime message — if there was one.

“It wasn’t really frustrating because we knew it was all on us,” Trent Williams said. “It was nothing they were doing… If we don’t shoot ourselves in the foot, we’ll get everything we want.”

But to be that team, the Niners needed Purdy to look like a $60 million man.

He was money in the second half.

The Niners drove down the field in five plays to start the second half, with George Kittle’s 43-yard catch-and-run (remember those?) setting up a 4-yard touchdown run from Isaac Guerendo.

Deommodore Lenoir followed that series by intercepting Dak Prescott with an acrobatic sideline swipe, giving the Niners the ball on the Dallas 32. Seven plays later, the Niners were in the end zone again.

The defense locked down for a three-and-out — one of four consecutive three-and-outs Dallas had between the end of the second and the start of the fourth quarters — and then Purdy, with a bit of brilliant improvisation on a scramble play, drove the Niners 75 yards on nine plays to jump out to a 27-10 lead.

“We had some missed opportunities in that first half, especially on third downs,” Purdy said. “A lot of that was on me.”

“For me, I was just being real with myself, and knew I had to be better,” the Niners quarterback continued. “I gotta get back to basics and keep things simple in my mind. Still playing with conviction but still being aggressive. Just trusting in my guys.”

That’s not easy. Sure, throwing to Kittle is straightforward, but Purdy worked with rookies, deep-roster players, and a limited Deebo Samuel.

He did what was necessary. He made it work anyway. That’s what excellent quarterbacks do.

And yes, the Niners nearly gave it all away in the fourth quarter — what’s new? — but they made enough plays late to run down the clock with the lead intact.

Now the Niners — and observers — can step off the hamster wheel momentarily, take stock of what has already happened this season, and re-calibrate for a harrowing second-half schedule.

“We can be whoever we want,” Fred Warner said.

He wasn’t talking about Halloween, either.

Does this team have enough to achieve its singular goal?

If Christian McCaffrey can return from injury — remember when he was supposed to play in Week 1? — they just might.