NEW YORK — Welterweight world titlist Terence Crawford, one of boxing’s elite pound-for-pound fighters, struggled at times against mandatory challenger Egidijus Kavaliauskas on Saturday night at Madison Square Garden, but eventually he did what he usually does — close the show in impressive fashion.

Crawford scored three total knockdowns in a ninth-round knockout victory over heavy underdog “Mean Machine” to retain his 147-pound world title for the third time before an announced crowd of 10,101.

Although he scored a knockdown in the seventh round and two more in the ninth, Crawford took his share of blows and looked shaky at times.

“I thought I had to entertain y’all for a little bit,” Crawford said. “He’s a strong fighter, durable, and I thought I’d give the crowd something to cheer for.”

Crawford, who fights for Top Rank and on ESPN, has wanted a big fight, but since all of the other elite welterweights fight under the Premier Boxing Champions umbrella and on other networks, he has not been able to land one of those fights.

Eleven years into his career and having won a lightweight world title, the undisputed junior welterweight world championship and a welterweight belt, Crawford still has not had a marquee fight. But after this performance, which he closed ferociously but had some issues, perhaps he will get one.

“The Lithuanian is a courageous guy, a very good fighter,” Top Rank promoter Bob Arum said of Kavaliauskas. “We always knew he was a very good fighter. He wasn’t an easy out. He wasn’t a walkover guy. He has tremendous heart and Crawford was able to get him out of there. You have to give Crawford credit for that.”

Crawford, who typically starts fights in a right-handed stance and later switches to southpaw, boxed in a left-handed stance from the opening bell and spent the first round out-jabbing Kavaliauskas, who seemed hesitant to let his hands go.

It was more of the same in the second round, in which Kavaliauskas did land one good right hand but could do little else to penetrate Crawford’s defense.

But in the third round Kavaliauskas landed a right hand that caused Crawford to grab him, and when Kavaliauskas fired several more shots, Crawford went down to a knee for an apparent knockdown. However, referee Ricky Gonzalez ruled it a slip.

“It looked like it was a really good punch,” Arum said.

Crawford insisted he was not hurt.

“I wasn’t hurt at all,” Crawford said. “I got up and went straight to him. I wasn’t hurt by no means. I walked through everything he threw all night.”

Kavaliauskas landed several more right hands in the fourth round that got through cleanly and knocked Crawford off balance. By the end of the fourth round Crawford had swelling on the outside of his right eye. Kavaliauskas was landing way more clean punches on Crawford than anyone is used to seeing.

Kavaliauskas landed a terrific right-left combination down the middle that knocked Crawford off balance early in the seventh round in what was becoming a dogfight.

Later in the seventh round, Crawford landed a solid right hand behind the ear and an unsteady Kavaliauskas went down a knee. He got up quickly and absorbed tremendous punishment over the final 15 seconds of the round.

Crawford (36-0, 27 KOs), 32, of Omaha, Nebraska, also had a big eighth round. He landed a big right uppercut that hurt Kavaliauskas and forced him to hold as the crowd chanted “Crawford! Crawford!” Later in the round, Crawford buckled Kavaliauskas’ knees with two powerful right hands.

Crawford finished him in the ninth round. Early in the round, he knocked Kavaliauskas back with a combination and then unleashed a right uppercut and a right hand to the head that sent Kavaliauskas (21-1-1, 17 KOs), 31, a 2008 and 2012 Olympian from Lithuania, who fights out of Oxnard, California, into the ropes and down to a knee. He beat the count and Gonzalez gave him a long look but allowed the fight to continue.

But it lasted only a few more seconds as Crawford immediately nailed Kavaliauskas with a right hook to the head that dropped him to a knee and Gonzalez immediately waved off the fight at 44 seconds.

“The round before that, my coaches kept telling me stop loading up,” Crawford said. “I was loading up a lot because the first couple of clean shots I landed, I knew I hurt him. I wanted to give the crowd a knockout. When I started letting my hands go, I started landing more fatal shots.”

Crawford led 79-72, 79-72 and 78-73 at the time of the stoppage. According to CompuBox, Crawford landed 128 of 382 punches (34%), and Kavaliauskas landed 118 of 391 (30%).

Now comes the difficult task of lining up Crawford’s next opponent. Arum thinks it might come against former welterweight world titlist Shawn Porter, one of the PBC top welterweights along with titleholders Manny Pacquiao and Errol Spence Jr. and former titleholders Danny Garcia and Keith Thurman.

“Shawn Porter said [a few days ago] it’s not for the promoters to decide,” Arum said. “He said if he and Crawford decide to fight each other they’ll tell us and then the promoters will follow the fighters’ wishes. That’s where I stand. Let Crawford and Porter, who are very good friends and great fighters, talk. If they want to fight [Porter adviser and PBC chief] Al [Haymon] and I will make the fight.”

Porter is coming off a very close decision loss to Spence in a unification fight in September. Spence is out for the time being recovering from a car accident.

“I think that Porter is the most competitive with Crawford right now (with Spence sidelined) and the reason I say that — and I didn’t say that before the Spence fight — is Porter lost by a whisker. He and Spence that night were equal. So Porter is the next best guy. He proved himself with Spence.”

Whether Crawford fights Porter next or can get one of the other top 147-pounders remains to be seen, but he is anxious to fight one of them with his résumé still in need of a defining fight.

“I’ll fight anybody,” Crawford said, as usual. “I’ve been saying that for I don’t know how long. I’m not ducking anyone on the PBC side or Top Rank platform. I want to fight all the top guys.”