World champion Verstappen held on to provisional pole after the first of two hotlaps with a 1m40.445s in his Red Bull RB19, with Leclerc posting an identical lap time to go second, because the Dutchman had set the time first.
On the deciding run, Verstappen could only find a minimal improvement to a 1m40.391s, while his Ferrari rival put two tenths on him with a 1m40.203s.
It's the first time this season that Red Bull has failed to grab pole, with Ferrari having the edge on the world champions through Baku's tight corners.
Afterwards, Verstappen explained a different approach on his out-lap may have cost him time.
"It's always tough around here to really put the whole lap together," he said. "I think also the second run we tried something different on the out-lap, which maybe was not ideal for the lap time at the end.
"But around here, it's just really hard. In Q3, you're on the limit and then trying to make everything perfect; it's not the easiest.
"But nevertheless, we're P2 we know that we have a very good race car. So, all in all, it's not bad, but you always want to start ahead, but we'll have to pass one car."
Verstappen's team-mate Perez followed in third, three tenths behind Leclerc, after an error in Turn 3 on his final lap cost him at least a tenth.
"It was really challenging, I think the team has done a great job," the Mexican said. "I'm a bit disappointed to be sitting in P3, because I felt definitely there was more in it.
"My lap wasn't that clean. But if there a circuit where you can race it is definitely here.
"We knew coming here that the Ferrari was going to be the biggest threat to us. I think Charles has done a tremendous lap as well."
Friday qualifying for Sunday's grand prix was the first competitive session of a new sprint format which meant drivers only had a single practice session to prepare.
Combined with a challenging, low-grip street circuit it meant mistakes were easy to make, with Q1 red-flagged twice for crashes by AlphaTauri's Nyck de Vries and Alpine man Pierre Gasly.
Perez thought the stoppages made it even harder for drivers to get into the rhythm.
"It was pretty tricky in Q1 with the amount of red flags that we had there and then sticking to the same set as you don't want to waste any more sets in Q1," he added.
"So, that was difficult to warm up and just to get through without making mistakes, without much practice."