Answer: 9.

Solution. In the last two hours, at least 9 people voted for Vasya. This means that in the end, he received at least 9 votes. Then Petya received no more than $27-9=18$ votes. Therefore, his lead in votes does not exceed $18-9=9$.

Now let's provide an example of how a lead of 9 votes could be achieved. Suppose that in the first hour, 18 people voted for Petya, and in the second hour, 9 people voted for Vasya. It is easy to see that all the conditions of the problem are satisfied, and Petya won with a lead of 9 votes.
Problem 7.7. In the election for class president, Petya and Vasya competed. Over three hours, 27 students in the class voted for one of the two candidates. In the first two hours, Petya received 9 more votes than Vasya. In the last two hours, Vasya received 9 more votes than Petya. In the end, Petya won. By what maximum number of votes could he have won?