CLEVELAND — Nobody’s perfect.

In a wild Game 4, the Cavaliers staved off elimination Friday night and kept their slim hopes of repeating as champions alive by doing some things no team had done before in the NBA Finals and something no team had done this postseason: They beat the Golden State Warriors.

They let the Warriors know they wouldn’t be celebrating on the Cavaliers’ court, wouldn’t be popping champagne in their building. They scored an NBA Finals-record 49 points in the first quarter and buried the Warriors, 137-116, at Quicken Loans Arena.

Kyrie Irving scored 40 points and LeBron James recorded his third straight triple-double, racking up 31 points, 11 assists and 10 rebounds.

The Warriors, who had been 15-0 in this postseason, lead the series 3-1 and can close out the Cavaliers at home in Game 5 on Monday night. No team has ever gone undefeated in the postseason, but if the Warriors win Game 5, they will end up 16-1. The 2000-01 Lakers currently hold the mark at 15-1.

“We knew this team was beatable,” Cavs coach Tyronn Lue said. “We knew we could play better. This is the result you get when we play at our best.”

advertisement | advertise on newsday

The Cavaliers — who missed eight free throws in the first quarter but still took a 49-33 lead — also set Finals records by scoring 86 points in the first half and hitting 24 three-pointers (in 45 attempts).

“We played a desperate team on their home floor, a great team with great players, and they came out and handed it to us,” Warriors coach Steve Kerr said. “Simple as that.”

The game also featured seven technical fouls, James and Kevin Durant jawing at each other, one flagrant foul, an ejection that turned out not to be an ejection (there were numerous puzzling calls by the referees) and a fan being thrown out after exchanging words with some Warriors near their bench.

When asked about the officiating, Kerr said, “Nice try.”

Durant led Golden State with 35 points and Draymond Green had 16 points and 14 rebounds, but Steph Curry and Klay Thompson totaled 27 points and 8-for-24 shooting.

NBA videos

The Warriors had won 30 of their last 31 games dating to the regular season. “We haven’t felt this feeling walking off the court with a loss in a while,” Curry said. “But we’ve done a great job of bouncing back and being resilient all year.”

Few gave the Cavaliers a shot to extend the series, especially after they squandered a six-point lead late in Game 3 as the Warriors scored the final 11 points of the game. But the Cavaliers showed their championship mettle and played like a team that didn’t want its season to end.

“Getting swept is something that you never want to happen, especially at this point when you get all the way to the Finals,” James said. “You hate to get swept, lose two games on your home floor. I think a lot of guys had in their mind and they came out and played like it.”

In the first half, Irving shot 11-for-14 and scored 28 points and James was 7-for-11 and had 22 points.

Kevin Love finished with 23 points for the Cavaliers, who are trying to become the first NBA team to win a postseason series after falling behind 3-0.

advertisement | advertise on newsday

They’re no strangers to unprecedented comebacks. Against the Warriors last year, they became the first NBA team to erase a 3-1 deficit in the Finals and win the championship. But the Warriors are much different, much more talented and determined to get that fourth win they couldn’t get last year. They also didn’t have Durant, who has been the MVP of the series thus far.

Things got testy in the third quarter after Durant drove and got hit in the head by Love. Durant and James jawed at each other and were hit with double technicals. Love was assessed a flagrant foul. That was the start of the craziness.

In the third quarter, Green was whistled for what appeared to be his second technical foul. That’s usually an automatic ejection, but he remained in the game.

The referees said Kerr received the technical in the first half, not Green. That was news to Kerr and everyone else. The first-quarter and halftime box scores said the technical was on Green, but it was changed to Kerr after that.

“I thought they called it on Draymond,” Kerr said. “I thought I heard the PA announcer say Draymond. The second one, I thought Draymond was going to get kicked out, but they explained the first one was on me.”

advertisement | advertise on newsday

Later in the third quarter, a skirmish for a loose ball resulted in Iman Shumpert and Zaza Pachulia getting into it. As the referees reviewed the play — it appeared Pachulia took a swipe at Shumpert — some Warriors, including Matt Barnes, had words with a fan by their bench. The fan was ejected and escorted from his seat, and Pachulia and Shumpert received double technicals.

The Warriors opened the fourth by scoring eight consecutive points to move within 115-104, but Irving answered with back-to-back baskets — a three-pointer and a floater — and James fed Richard Jefferson for a layup to push the lead to 122-104 with 7:44 remaining.

The Warriors got within 126-111, but back-to-back three-pointers by J.R. Smith and Irving put the Cavaliers up 21 with 2:16 to go.

“We’re a resilient group, a resilient team,” Love said. “We never count ourselves out.”