Alonso was beaten at the death by reigning F1 world champion Max Verstappen.
Verstappen put together a blistering final sector to pip Alonso to his first-ever pole position in Monaco.
Reflecting on qualifying in the principality, Hamilton praised Aston Martin for their “phenomenal work” in F1 2023.
“I’ll take anything I can get,” Hamilton said. “When you think about it, we are having to rely on others currently. So when you have Checo in the wall it’s like ‘thank you!'”
“Ocon came out of nowhere, “He did obviously a great lap. I was really hopeful Fernando [Alonso] would have pole at the end. I saw it and I was like, ‘oh, this could be amazing for him’. But that Red Bull was just too quick.
“But that Aston is now almost on par with that Red Bull, that’s phenomenal work. So I’m really happy for Aston and I hope that we can be there soon.”
Hamilton recovered from his crash in FP3 to secure sixth on the grid for Sunday’s race, two places ahead of teammate George Russell.
The seven-time world champion was nearly knocked out twice during qualifying, with Hamilton admitting “my heart was in my mouth”.
“I didn’t try to leave it late, it’s just how it turned out,” Hamilton added.
“Our middle sector has been where we’re losing out all weekend so far. So I made a change over into qualifying which made it harder in the first and last sector. You can’t always have your cake and eat it.
“But I struggled to get temperature into the tyres in the session and so it was always that last, last lap that I managed to just pull something out.
“But my heart was in my mouth because it was like there could be a yellow flag, could be a red flag, who knows? But we made it through and I’m grateful for the lap we got.”