The British driver, who clocked the fastest lap of one hour and 17.281 seconds, was was just 0.013 seconds ahead of Bottas, the Formula1.com reported.
Vettel will line up in third after qualifying 0.132 seconds slower than Hamilton. Things didn't go almost as well for many other top drivers, though, as Valtteri Botas blew a tyre in the final stages, while Red Bull teammates Daniel Ricciardo and Max Verstappen each failed to finish the race for the second time this season.
Kubica finished with the second-to-last time in the first session, in front of teammate Lance Stroll.
It was a record-extending 74th pole for Hamilton, and the first since the season-opener in Australia.
"If it's within one tenth, tenth and a half you always think maybe but to be honest I was very happy with the lap until the end".
"Q3, the first run, I locked up a little bit into Turn 1 so the first sector was already slow and I tried to get back and recover, but to really fight for pole it was not enough and I didn't get a great feeling on that tyre, on that set so I chose to ask to go back and I think it was the right call".
Vettel felt sure he had done enough to get the better of Hamilton with a stunning final lap, but still came up short and is anticipating "an interesting race".
Embraer just debuted its Uber Elevate flying taxi concept
The flying cars are expected to conduct vertical takeoffs and landings from skyports, air stations on rooftops or the ground. Uber also announced that it signed an agreement with NASA to share its plans for implementing its flying rideshare network.
"We were very good here in winter testing and we have definitely improved since then". The vehicle was fine and we didn't have much to do.
"Not to say that we know everything, we don't anything about engineering the auto, but we know how the cars feel, how to drive the cars, and their limitations to overtake".
"Hopefully we see some action and we take benefit from that".
"For tomorrow though I think we should be in the mix", he added.
"It is a constant learning process but these tires they seem to have a small working window whether they give us more rubber or less rubber they appear to be a lot harder than a year ago even though they went softer".
Kimi Raikkonen, in the other Ferrari, was sixth fastest in the afternoon and had to retire late because of an apparent engine problem. It's hard to predict what will happen in the race and it's a bit of an unknown for me, considering I couldn't do the long runs yesterday.