Canelo Alvarez and Gennady Golovkin fought 24 rounds in the space of a year, with little to pick between them.

When the scorecards were totaled Saturday night, though, the judges crowned a new middleweight champion of the world — but just barely.

Alvarez won the 160-pound titles held by Golovkin by the narrowest of margins, taking a majority decision to hand the longtime champion his first loss as a pro in a spirited fight that had a sold out crowd roaring.

Two judges gave Alvarez the final round, allowing him to pull out the win.

A year after the two fought to a draw, the second fight was almost as close. There were no knockdowns, but the action was spirited throughout as the two battled to the final bell before a frenzied crowd at the T-Mobile Arena.

Two judges favored Alvarez 115-113, while a third had it 114-114.

“He’s a great fighter but I’m a great fighter and I showed it tonight,” Alvarez said.

The two fighters switched roles from their first fight, with Triple G trying to counter Alvarez and the Mexican fighter coming forward much of the fight. Both landed well to the head and Golovkin (38-1-1) controlled some rounds with his jab though neither were ever in any trouble of going down.

The fight was a rematch of a draw last September that left neither fighter satisfied. This time it was Golovkin who was upset, and he stormed out of the ring without talking.