Under dark skies and with spots of rain falling on the Montmelo track, Lorenzo snatched the lead with just under six laps left and pulled away from Honda's Pedrosa to secure his third victory in five races this season.
Italian Andrea Dovizioso was third on his Yamaha, with Pedrosa's Honda team mate and defending champion Casey Stoner of Australia fourth and Britain's Cal Crutchlow, another Yamaha rider, fifth.
After planting his signature flag in the gravel in front of his ecstatic fans, Lorenzo told Spanish television it was "fantastic" to win in front of home support.
"It was a finely balanced race," added the flamboyant 25-year-old, the 2010 MotoGP champion.
"I didn't want to do anything crazy as we were riding very close together and there was a danger of colliding and ending up on the ground.
"I had to wait for my chance and as you saw I managed to get past him."
Lorenzo's victory extended his lead over Stoner in the standings to 20 points and the Spaniard now has 115 after five of 18 races. Stoner, who said last month he would retire at the end of the season after falling out of love with the sport, has 95 and Pedrosa 85.
Pedrosa admitted to being "a bit disappointed" with his race, especially after he rocketed from fifth on the grid to lead into the opening corner.
"I thought I would be able to perform better towards the end of the race but I had to settle for second," he told Spanish TV.
"I tried my hardest but I found it very hard to control the bike when braking on the final laps."