ST. PETERSBURG, Fla. — The Red Sox finished a 3-2 loss to the Rays under protest on Wednesday afternoon after Alex Cora disagreed with the way umpire Angel Hernandez handled some unusual lineup changes by the Rays.

The result was a delay that lasted more than 20 minutes as more than 24,000, most of them children, at Tropicana Field waited for play to resume without any announcement of what was going on.

“It was a mess,” Cora said afterward.

The Red Sox were down 3-2 in the eighth inning when the Rays replaced starter Charlie Morton with lefty Adam Kolarek to start the inning. Kolarek retired pinch-hitter Sam Travis before Rays manager Kevin Cash went to his bullpen and summoned righty Chaz Roe to face the right-handed Mookie Betts.

Kolarek, though, never left the game. Instead, he moved over to first base and replaced Ji-Man Choi, thus keeping Kolarek in the game to pitch again later, after Betts was retired and another left-handed hitter, Rafael Devers, was due up.

Devers was later retired on one pitch by Kolarek. But not before a long delay over confusion about the lineup changes.

The move to keep Kolarek in the game at another position, then return to pitch, is legal and within the rules, but the way Hernandez handled the lineup card is what seemed to have set Cora off.

“There’s a lot there,” Cora said. “They brought in the lefty (Kolarek), and then they brought in Roe for Choi. They kept the DH at that moment. So they had a pitcher, a first baseman, they had a pitcher on the mound and they still had a DH. It’s kind of hard to explain. I’m sorry I can’t go over it because there’s a lot. It’s an illegal substitution so we’ll see what happens.”

But even though Kolarek replaced Choi, who was hitting ninth, Kolarek ended up in the three spot in the batting order, replacing DH Austin Meadows. And Roe ended up replacing Choi in the nine spot in the order.

The order was never clearly announced to Cora, which was why he had a gripe.

“When he brought in the lefty and we saw what was going to happen, when he put him first at I asked Angel about it and he gave me an answer,” Cora said. “I’m like, ‘OK, this is about to get interesting.’ And it did.”

Cora spent around 15 minutes on the field arguing with the umpire crew until he made it clear the Red Sox would play the game under protest. At that point, the umpires went to the headsets and called down to the headquarters in New York.

MLB then announced that Cora was playing under protest “due to the placement of the substitutes in the lineup following the removal of the DH.”

After the game, Hernandez told a pool reporter that Cash never made it clear which spot in the batting order Kolarek would take over when the Rays lost their DH. He cited rule 5:11, which notes that if the manager doesn’t designate where the pitcher is hitting in the event of multiple changes, the umpire can decide. So Hernandez put Kolarek in the three-spot, which made Cora upset.

“He wanted to know what was going on, so we told him it didn’t alter the outcome of anything that had happened so far,” Hernandez said.

So that doesn’t leave any room for Cora to protest?

“Exactly,” Hernandez said. “That’s what we were trying to tell him. But he wanted to protest. We went to headsets to verify but it takes a long time to explain that.”

The end result had nothing to do with the outcome of the game, making Cora’s protest unlikely to influence MLB in a way that would force the two teams to replay the game from the moment in question.

Instead, it will likely go down as a 3-2 loss for the Red Sox, who had a 2-0 lead early against Morton but David Price couldn’t hold it.

Rafael Devers came through with another clutch hit to score two in the third inning after Brock Holt and Betts reached base against Morton. Devers poked a grounder through the hole on the left side for his 78th and 79th RBIs of the season.

But Price allowed a homer to Tommy Pham in the fourth and two more runs on three hits in the fifth as the Rays held on for the win.

Asked what his view was of the eighth-inning chaos, Price said, “A long delay. I don’t know the rule book like that. I don’t know. That was a very long time.”

For the first time all year, the Sox had pulled even with the Rays in the standings on Tuesday after taking the first two in this series, but couldn’t finish the job and moved back to third place in the American League East ahead of a key four-game series against the Yankees at Fenway Park. The Rays return to Fenway next Tuesday.

“We’re confident we got it right at the end of the day,” Cash said afterward. “My big concern is whatever is taking place, can we speed it up? Because I have a guy on the mound (Kolarek) who is just standing there, which is a little uncharacteristic in a game, in any game, and it was tight at that point.”