Sometimes boxing is a complete mess. And sometimes, it’s beautifully, wonderfully, poetically just.

Carlos Baldomir’s upset of Zab Judah last week is an example of the latter.

Here’s a challenger, Baldomir, who is 32 years old, fighting thousands of miles away from his homeland in his first world title fight, against a fighter who is regarded as one of the best in boxing.

He’s given zero chance of pulling off an upset, mostly because he has just 12 knockouts in 41 fights. And because he is painfully slow and untalented — especially compared to the gifted champion.

He is virtually dismissed before the fight, to the point that champ’s next title defense is adone deal.

But the oddsmakers and the fight experts and, especially, Judah’s camp, underestimated the challenger. They underestimated his hunger. They underestimated his guts.

And they underestimated his heart.

And once Judah pulled the cheap shot of the decade — whacking Baldomir on the ass during the pre-fight introductions — it became easy to root for the tough Argentine.

What was going through Judah’s little mind as he reared back and fired a shot against a defenseless opponent?

Not much, apparently.

Had this been the only time Judah exhibited chicken crap behavior, OK. But throughout his career, the Brooklynite has become known for his boorish, immature, spoiled-brat antics.

Referee Arthur Mercante Jr. was too gutless to punish Judah for the pre-fight punch. So Baldomir did it for him.

The Baldomir right hand that made Judah’s legs go spaghetti in the seventh round was a gift from heaven for those of us who were repulsed by Judah’s inexplicable attack. It was as if God touched Baldomir’s head and said, “For one night, I grant you a hard punch. This guy you’re fighting is a jerk.”

So the rest of the fight was Baldomir chasing Judah all over the ring, because the champ didn’t have the professionalism — no, make that, the common sense — to train for what amounted to the biggest fight of his life.

He wins, and he is a millionaire. Apparently, that wasn’t enough motivation for Zab.

By the end of it, no one really cared about Judah’s lame excuses, especially the one about his promoter, of all people, running him ragged the week of the fight. For once, Don King was a sympathetic figure. What was Mr. Fuzzy Hair supposed to do? Hold down Judah’s feet while he did sit-ups?

And isn’t a fighter pretty much supposed to be finished with training by the time fight week arrives anyway?

The decision, despite the irrational rants of Judah’s father, was perfect. It was simply unexpected, it being Zab’s hometown and all.

And now we have a new welterweight champ.

Yes, boxing gets it wrong a lot of the time. But, some of the time, it gets it very, very right.