Alonso had pitted to replace the blown tire, then pitted again a couple laps later. At that time, when he exited the pits, there was around 1:30 remaining in the session. Alonso had to hustle to circulate a lap before the clock expired, so that he could get one last qualifying lap in. Massa was never withing 30 meters of Alonso, until exiting the parabolica, where to be honest, downforce is the most important. I do believe that Massa being behind Alonso did affect his lap times. But There was no way Alonso could give way, in fact the closely following Massa didn't cross the finish line until after the clock had expired, while Alonso made it by the skin of his teeth, maybe a second or less.
Alonso was just out there trying to get a decent lap in, he should not have been penalized.