What was supposed to be history descended into histrionics.

Serena Williams came into Saturday’s US Open final looking for a record-setting title. What she got was a game penalty and an emotional meltdown.

It overshadowed Naomi Osaka’s 6-2, 6-4 win over her idol for her first Grand Slam title, and put a mark on the Open’s golden anniversary.

Though Williams repeatedly demanded an apology from chair umpire Carlos Ramos and got a game penalty after calling him a “liar” and a “thief,” she ended the match in tears. And Osaka — who sat in the stands at Arthur Ashe Stadium when she was 5, watching Williams play — was in tears herself as the pro-Williams crowd rained boos upon the victor’s stand, which included USTA officials.

All in all it was a pitiful scene, Williams actually getting her apology from Osaka instead of Ramos.

“I know everyone was cheering for her. I’m sorry it had to end like this,” said a tearful Osaka, 20, so shaken that she nearly dropped her trophy. Meanwhile, Williams — who’d regained her composure — put her arm around her young foe and implored the crowd to stop booing.

“I felt bad because I’m crying and she’s crying,” said Williams. “She just won. I’m not sure if they were happy tears or they were sad tears because of the moment. I felt like, wow, this isn’t how I felt when I won my first Grand Slam. I was like, wow, I definitely don’t want her to feel like that. Maybe it was the mom in me that was like, ‘Listen, we got to pull ourselves together here.’ ”

Williams had come in seeking a milestone win, one that would’ve tied Margaret Court’s all-time record for Grand Slams (24). But Osaka — and Williams’ own temper tantrum — scuttled those plans.

In the second game of the second set, Ramos hit Williams with a code violation for receiving coaching from Patrick Mouratoglou from her player’s box.

“You owe me an apology,” Williams said. “I’ve never cheated in my life. I have a daughter and stand for what’s right for her.”

Still, Mouratoglou admitted he’d given her advice, though he threw in the disclaimer that she may not have seen it from the other end of the court.

“I just texted Patrick, like, what is he talking about? Because we don’t have signals, we’ve never discussed signals. I don’t even call for on-court coaching,” Williams said. “I’m trying to figure out why he would say that. I don’t understand. Maybe he said, ‘You can do it.’ I was on the far other end, so I’m not sure. I want to clarify myself what he’s talking about.”

Williams got a second code violation four games later, up 3-2. After Osaka broke her serve, Williams broke her racket in frustration and was assessed a point penalty.

“You will never, ever be on another court of mine as long as you live. You’re the liar. When are you going to give me my apology? Say it! Say you’re sorry!” Williams ranted, before ending with, “You’re a thief, too.”

That was the last straw, and Ramos hit her with a third code violation for verbal abuse, which cost Williams a game to put Osaka up 5-3. An irate Williams argued in vain to tournament referee Brian Earley and got closed out two games later.

The US Open released a statement saying “the chair umpire’s decision was final and not reviewable by the Tournament Referee or the Grand Slam Supervisor who were called to the court at that time.” Williams contends that the letter of the law wouldn’t have been followed if she were male.

“I’ve seen other men call other umpires several things. I’m here fighting for women’s rights and for women’s equality. For me to say ‘thief’ and for him to take a game, it made me feel like it was sexist,” Williams said. “He’s never taken a game from a man because they said ‘thief.’ For me, it blows my mind.”