OAKLAND — The Boston Celtics almost withstood it all.

Stephen Curry’s remarkable 49-point performance. A four-minute second-quarter drought. Another rough spell at the start of the third quarter. The crazed Oracle Arena crowd, which can help transform Golden State Warriors runs into avalanches. The absence of Marcus Smart, one of their top defensive options against Golden State’s many sharpshooters. And, of course, the Warriors themselves – maybe the NBA’s most talented team ever.

Even after their 109-105 loss Saturday night, the Celtics left the Bay Area with a sense of optimism, knowing they gave themselves a chance for a third straight win against the defending champs while mangling a few switches against Curry and losing their offensive composure during a couple stretches. They failed to close out the Warriors after taking a late fourth-quarter lead, but built even more confidence in a defense that has stood strong when the stakes are highest.

“As a group, obviously, we want to win these games, but for our group, it’s more about making sure we play well and we keep improving throughout the season,” said Al Horford, who finished with 15 points and 13 rebounds. “This is kind of like – everything we’re preparing for (is) the postseason. I felt like we took a step forward today even though we lost.”

A step forward? Well, the Celtics entered Saturday with four losses in their last five games. Their offense was ranked dead last in the NBA in January. They had frustrated the coaching staff with their lack of execution and held a team meeting to try to figure out their woes.

Yes, building two double-digit leads against the Warriors qualified as improvement.

Curry and Kyrie Irving have put on breathtaking shotmaking displays against each other before, but even by their standards, Saturday’s game was special. Curry scored 49 points, and Irving responded with 37. And they managed a startling level of efficiency against elite defenses loading up to stop them.

The Warriors sent a number of hard double teams toward Irving, but he still scored 14 points in the first quarter and another 12 in the fourth. The Celtics set out to limit Curry, but he still erupted for 18 points during the decisive third quarter, carrying his team out of a four-point deficit and into an 80-73 advantage. He followed up with 15 points in the fourth, including eight straight free throws down the stretch. On almost any other night, Irving’s performance would have blocked the sun from everybody else’s accomplishments. On this one, Curry topped him.

“They both shot the ball incredible tonight,” said Horford. “Kyrie, from the beginning of the game, you knew he was in another zone, and Steph, obviously, was the same way. A great battle.”

“You just got to sit back and enjoy the show,” explained Kevin Durant. “You know what I’m saying? Once they got it going, you got to get out the way.”

It seemed like Irving and Curry took advantage of every defensive slip-up. After Jaylen Brown botched one second-half switch, allowing Curry to step into a clean 3-point look, Celtics Coach Brad Stevens threw his hands into the air in temporary misery.

“I thought we made some mistakes with our hands down,” Stevens said. “He’s gonna make some of those shots off of the screen, especially when he gets into that rhythm where he basically pulls up. He looks like he’s just gonna turn and run back on defense knowing it’s gonna go in. And then we missed some switches, and you just can’t do that. He’s too good, and so probably we’ll go back and look at that and there’ll be two or three that maybe we could’ve controlled a bit better, but for the most part, it still doesn’t mean you’re gonna stop him from scoring.”

As for Irving, Stevens said, “He’s awfully tough. There’s no question about it. And they threw a bunch of different bodies on him and he just kept going and going and going. He had a special performance, I thought.”

The most important takeaway for the Celtics was that their defense again held up relatively well against top competition, despite Curry’s big night. Durant went 7 for 18 from the field, marking just the fifth time this season that an opponent has held him below 40-percent shooting. Klay Thompson failed to hit a 3-pointer for just the third time all season. The Warriors set a season low with 19 assists.

“It was much more of an isolation-style game than we would like,” said Warriors Coach Steve Kerr. “But that’s what they do. That’s why they are the best defensive team in the league.”

The Celtics’ defense hasn’t just feasted on weak opponents. It has proven itself against all the best offenses, looking like the type of unit that can give Boston a chance almost every night – even when Curry goes off, when bench lineups don’t always produce, and when scoring droughts become normal occurrences.

“I feel like we’re getting even better individually preparing ourselves in terms of personnel and the plays that teams are throwing at us,” Irving said. “We just have to have it on a consistent basis. Whatever the team does, our defense, it’ll get us some wins. And we trust that.”

The last two sentences of that quote might have been the most important any Boston player spoke Saturday night. For all the talk about the Celtics’ recent scoring woes, the team’s defense has emerged as a special group. The Warriors rarely feel their opponents’ defense, but obviously felt the Celtics.

Still, the Celtics fell short. After realizing his big night was not enough, Irving called the Warriors “a Goliath of a team” and preached how much he enjoys competing against the best. Durant and Draymond Green acknowledged they could see Boston again in the NBA finals, but, as Durant said, “Who knows with that.”

Golden State has accomplished everything together already. Boston is still figuring things out as a group.

“I’m looking on the floor at a new team,” Irving said. “And we’ve got Jayson Tatum, Jaylen Brown and Semi Ojeleye, Daniel Theis, and they’re just thrown into the high-level, 1-seed vs. 1-seed type of battle. It demands everything from you mentally, physically. You’ve gotta bring it because you’re going against the champs. And being in Oracle, high-level, they go on their run, Steph’s being unbelievable, the crowd’s going crazy, it’s a lot to consider.

“For us, we just take it as a learning experience. And I told them before the game, just take advantage of the opportunity and stick together, and be able to weather the storm. They’re an incredible team, but we’re a developing young team as well – trying to be great as well.”