At UFC 202 in Las Vegas on Saturday night, Conor McGregor got his revenge on Nate Diaz, turned his nemesis’ face into a bloody mess and declared he was the UFC’s top dog once again.

“Surprise, surprise,” McGregor said after the fight. “The king is back.”

McGregor’s typical bluster did not match the relief on his face because it belied the truth everyone saw in the Octagon: Diaz almost beat him. Again.

For the first round-and-a-half, McGregor was firmly on top as he took a page out of Rafael dos Anjos’ book by chopping away at the bigger man’s mobility with a slew of brutal leg kicks.

Unable to move laterally, Diaz was eventually dropped twice by the quicker McGregor, but just like in their first fight at UFC 196 in March, McGregor exhausted himself going for the knockout.

Visibly tiring at the end of the second round, McGregor could barely defend himself as Diaz pushed the smaller man against the cage and pounded him with some classic dirty boxing.

Throughout the third round, Diaz pressed the action and rocked McGregor on numerous occasions, but the Irishman showed some true grit, and unlike in their first fight, survived the onslaught.

McGregor’s toughness paid off in the fourth round, when he found his second wind and landed quick combinations of punches on Diaz, who was constantly wiping blood from his eyes.

Thus the two fighters entered the fifth round, exhausted but unyielding. McGregor drew in huge gulps of air and continued throwing combinations, but a zombie-like Diaz plodded forward and eventually took down McGregor — but with just seconds left in the fight, so it would be decided by the judges.

McGregor came out the winner by majority decision: Two judges scored it 48-47 for McGregor, and a third judge scored the fight as a 47-47 draw.

Here is what each fighter can take away from the fight:

Conor McGregor

Referee John McCarthy raises McGregor’s hand after the majority decision was announced.AP

Before fighting Diaz at UFC 196, McGregor was on a 15-fight win streak and was talking about himself as though he was God’s gift to martial arts.

The huge weight discrepancy proved crucial. The smaller McGregor just didn’t have the strength to knock out Diaz.

Saturday night’s fight confirmed the limits of McGregor’s size and power. Despite doggedly sticking to his game plan of repeated leg kicks and regimented punches, McGregor still couldn’t knock Diaz out. McGregor needs to realize he’s a 145- to 155-pounder, where his power is much more lethal.

Thankfully for McGregor’s legion of fans, he seems to know that fighting the much bigger Diaz at 170 pounds is a mistake he’s not going to make again.

“Like my coach says, ‘We live or we learn.’ I learned from our last contest,” McGregor said in the Octagon shortly after he was announced the winner. “All I know is that it’s 1-1, regroup and we’ll do it again, this time at 155 pounds. I came up to 170, faced the bigger man, overcame my adversity, now you want this trilogy, it’s on my terms. Come back down to 155, we’ll do it.”

Besides getting a lesson about fighting bigger men, McGregor and the fight world at large also learned McGregor actually can survive a fight he doesn’t dominate.

For McGregor’s entire pre-Diaz UFC career, he was a front-running fighter who dispatched his opponents with brutal efficiency.

It’s a quality all great fighters need, and it could turn McGregor into the MMA deity he already thinks he is.

Nate Diaz

Diaz wipes blood from his eyes during his fight against McGregor on Aug. 20.AP

“I thought I won the fight,” a defiant and bicep-flexing Diaz said in the cage after the majority decision against him was announced. “They can’t have a motherf—ker like me win. I’m too real for this sport.

“I came into this fight worse off than last time. I didn’t get to train, I had injuries … f–k that, I ain’t making excuses, but he should have finished me off. I want No. 3. I gave him No. 2 the second day, so I’m ready to go again. F–k yeah!”

All righty then.

Whether he’s “too real” for the judges or whatever, Diaz was not off his rocker to think he won the fight. Plenty of very smart people thoughtthe same thing.

The only problem for Diaz is it doesn’t really matter if he was robbed — either way, he’s back in the same purgatory he was stuck in before his first fight against McGregor.

At the time, Diaz was a favorite among hardcore fans because of his crowd-pleasing style and was coming off the best win of his career, against lightweight Michael Johnson. But Diaz wasn’t even close to being a title contender in any weight division.

His shocking win over McGregor thrust him into the spotlight, but the loss in the rematch casts him back into the fighting shadows.

Everyone knows Diaz is tough as nails and has world-class boxing skills, but he’s vulnerable to leg kicks (see: McGregor II and his fight against dos Anjos) and doesn’t have a Plan B.

Diaz is not better than dos Anjos. And McGregor, if he decides against a rematch with Jose Aldo at 145 pounds, just jumped Diaz’s place in line for a title shot against Eddie Alvarez at 155 pounds.