The Gresini rider qualified on pole for the first time on a Ducati before going on to score his first grand prix podium after a thrilling 25-lap race at Jerez on Sunday.
Marquez locked horns with Bagnaia in the latter stages of the grand prix, with the pair engaging twice at Turn 9 on laps 21 and 22.
On the first attempt, Marquez launched his bike up the inside of Bagnaia's at Turn 9, before the latter retaliated at Turn 10 as the pair ended up making contact.
Both survived this and Bagnaia came through into the lead, defending a second attempt from Marquez on the following tour.
Marquez ultimately lost out on the win by 0.372s to Bagnaia and admitted he was "a bit stiff" in the early laps having crashed out of the lead of the Americas GP and the Jerez sprint.
"It was an important race – a super important race," he said.
"In the beginning, I was a little bit stiff because I crashed in Austin, I crashed yesterday and in the beginning with the full [fuel] tank I was stiff and I lost some positions.
"But the speed was there to come back, the speed was there to fight with Bagnaia.
"It was a tight fight, even like old times. This is good, it's racing. I tried to close the door, but he was inside and this is something that happens in the racing.
"On the last lap, he was super good, he pushed, and he did the fastest lap of the race. And then I tried to follow him but he had a bit more.
"But I'm super happy for this first [grand prix] podium. As you see, it doesn't matter what happened in the past – just I fight until the end."
Second at Jerez marked Marquez's first grand prix podium since the wet Japanese GP last year, a few days after which he informed Honda he would be leaving the team at the end of 2023.
Not since the 2022 Australian GP has Marquez stood on a grand prix podium in the dry.
He now sits sixth in the standings on 60 points, 32 behind championship leader Jorge Martin after the Pramac rider crashed out of the Spanish GP while leading on lap 11.