Espargaro had led for the majority of the race after storming from sixth to first in a blistering start, with Jorge Martin dropping from pole to eighth early on.
It was Gresini's Bastianini, a rookie at this level last year, who made a dream beginning to the season, though, overtaking Espargaro with four laps to go and taking the chequered flag ahead of Brad Binder for his team's first win in the premier class since 2006.
Bastianini's win at the Lusail International Circuit sparked emotional scenes, as Gresini's then team principal Fausto Gresini died just over a year ago.
Espargaro was the third man on the podium, while Marc Marquez was fifth and Martin crashed out.
Repsol Honda rider Espargaro got off to a flyer as Martin slipped back through the field, with Bastianini dropping a couple of places from second on the grid.
Espargaro's team-mate Marquez moved up a spot from third to second until the six-time champion was passed by Binder and Bastianini with 16 laps to go.
Martin's miserable race was summed up when he crashed with Francesco Bagnaia and slid into the gravel along with the Italian.
Bastianini had the pace to close in on the long-time leader and duly made his move on the inside, with Espargaro going wide in a costly lapse that allowed Binder to nip in for second place.
1. Enea Bastianini (Gresini Racing)
2. Brad Binder (Red Bull KTM) +0.346
3. Pol Espargaro (Repsol Honda) +1.351
4. Aleix Espargaro (Aprilia) +2.242
5. Marc Marquez (Repsol Honda) +4.099
6. Joan Mir (Suzuki Ecstar) +4.843
7. Alex Rins (Suzuki Ecstar) +8.881
8. Johann Zarco (Pramac Racing) +10.536
9. Fabio Quartararo (Monster Energy Yamaha) +10.543
10. Takaaki Nakagami (LCR Honda IDEMITSU) ++14.967
1. Enea Bastianini (Gresini Racing) 25
2. Brad Binder (Red Bull KTM) 20
3. Pol Espargaro (Repsol Honda) 16
4. Aleix Espargaro (Aprilia) 13
5. Marc Marquez (Repsol Honda) 11
1. Repsol Honda 27
2. Gresini Racing 25
3. Red Bull KTM 20
4. Suzuki Ecstar 19
5. Aprilia 17