CLEVELAND — It was exactly the kind of win the Cavaliers needed, and ESPN certainly had no complaints.

With one second left in overtime, LeBron James took a long inbounds pass from Jeff Green and buried an 18-foot fadeway over Jimmy Butler, giving the Cavs a thrilling 140-138 victory over the Minnesota Timberwolves on Wednesday night at Quicken Loans Arena.

“Once I caught it, I just trusted everything I’ve done in my career,” James said.

The four-time league MVP, who tied the game at 138 on a drive with 24 seconds left in OT, helped set up his own heroics by coming over from the weak side and swatting a drive by Butler. J.R. Smith corralled the rebound and called time to set up Cleveland’s biggest victory of the season.

“I just tried to time it at the right time and use my athleticism and try not to knock it out of bounds,” James said.

The win was just the Cavs’ seventh in their last 20 games — they had lost their previous two by a combined 50 points — and improved their record to 31-22. It also ended an eight-game losing streak on national television and was their first victory in eight games against the top five teams in the Western Conference.

“It was a good win, but our record still stinks on national television,” James said. “We’ve got a couple coming up. We’ve got to change that.”

James finished with 37 points on 16-for-22 shooting, 10 rebounds and 15 assists while passing Zydrunas Ilgauskas for the all-time franchise lead in rebounds. He joined Michael Jordan (Chicago) and Kevin Garnett (Minnesota) as the only players to lead a franchise in career points, rebounds and assists while posing his ninth triple-double of the season and 64th of his career.

“That’s pretty good company,” James said of joining Jordan and Garnett. “I’m blessed.”

Cleveland also got 20 points from Smith, 17 from Tristan Thompson, 14 from Kyle Korver, 13 apiece from Green and Isaiah Thomas, who received a smattering of boos when he re-entered the game with 6:55 left in regulation and the Cavs up eight, 10 from Jae Crowder and nine from rookie Cedi Osman, who played big-time minutes in crunch time.

It was Osman who got switched onto Butler on the drive preceding James’ game-winner, but his teammate came to the rescue with a terrific block.

James was equally complimentary of the 22-year-old, saying, “His purity of the game is infectious to our entire team. He hasn’t been in many situations, so he’s not going to trip about what’s going on.”

At least not until after the game is over and he has time to think about it.

“It was amazing, seriously,” said Osman, who played 21 minutes. “The most important thing for us was to win tonight. We’ve been struggling. This was so important for us.”

The Cavs shot a sizzling .591 from the floor and made 21-of-41 3-pointers, with James going 5-for-7 from deep. The last time he had made even three 3-pointers in a game was Jan. 6.

“I’m always behind the scenes working on stuff,” the 33-year-old said.

Minnesota (34-23) was just as good on offense. Butler had 35 points on 14-for-21 shooting, five rebounds and six assists, while Karl-Anthony Towns had 30 points on 10-for-12 shooting and a perfect 6-for-6 3-pointers plus 10 boards. Andrew Wiggins had 19 points and Jeff Teague had 14 points and 15 assists.

In all, 13 players scored in double figures, with the T-Wolves shooting .581 from the floor and making 19-of-33 3-pointers.

“Any time you win a game like this, especially against a really good team like the Timberwolves, it gives you confidence,” Thomas said. “We’ve just got to build on it.”

The game was tied at 129 at the end of regulation after James disdained a drive or shorter jumper and missed an unneeded step-back 3-pointer over Butler at the buzzer.

Moments earlier, James had answered a Towns three with one of his own, off the dribble while fading to the left, to tie things with 45 seconds to go.

He saved his best for the very end, however, hitting a jumper that was eerily similar to the game-winner Duke’s Christian Laettner hit against Kentucky in the 1992 NCAA Tournament, except for the fact Green’s inbounds pass came from three-quarters court instead of the baseline.

“(Butler) played amazing defense on him, but he was having one of those nights,” Towns said. “The rim looked like an ocean.”

The game was entertaining throughout, with an abundance of terrific offensive plays and one rough sequence that stood out.

Moments after hitting a long jumper, Crowder came up with an open-court steal and was driving to the hoop when he got blatantly pushed from behind by Teague with 10:48 left in the third, resulting in a flagrant foul.

It was the closest either team came to stopping the other through the first three periods, after which the Cavs led 101-99.

James (13) and Thompson combined for 22 points as Cleveland won the third period 37-33. Minnesota’s Butler, Towns and Teague, meanwhile, had combined for 60 points on 22-for-30 shooting, including 9-of-11 3-pointers, at that stage.

Smith had a sensational first half for the Cavs, making 5-of-6 3-pointers en route to 17 points, but that was offset by a combined 37 points from Towns, Butler and Teague (and Cleveland’s 6-for-13 performance at the line).

“When he’s making shots for us, he changes the entire team,” Cavs coach Tyronn Lue said of Smith.

While realizing they still have work to do — and that changes could be made prior to the trade deadline at 3 p.m. today — the Cavs are hopeful the win might jump-start a change to their disappointing season.

“There’s definitely an upside to it,” Smith said. “We’ve just got to bottle what we did tonight.”

That included a joyous team-wide celebration after James’ game-winner.

“That was something we needed,” Green said. “The way we won was something we needed.”