In recent years, the evolution and the widespread adoption of virtualization, service-oriented architectures, autonomic, and utility computing have converged letting a new paradigm to emerge: cloud computing. Clouds allow the on-demand delivering of software, hardware, and data as services. Currently, the cloud offer is becoming wider day by day because all the major IT companies and service providers, like Microsoft, Google, Amazon, HP, IBM, and VMWare, have started providing solutions involving this new technological paradigm. As cloud-based services are more numerous and dynamic, the development of efficient service provisioning policies becomes increasingly challenging. In this paper, we take the perspective of Software as a Service (SaaS) providers that host their applications at an Infrastructure as a Service (IaaS) provider. Each SaaS needs to comply with quality-of-service requirements, specified in service-level agreement (SLA) contracts with the end users, which determine the revenues and penalties on the basis of the achieved performance level. SaaS providers want to maximize their revenues from SLAs, while minimizing the cost of use of resources supplied by the IaaS provider. Moreover, SaaS providers compete and bid for the use of infrastructural resources. On the other hand, the IaaS wants to maximize the revenues obtained providing virtualized resources. In this paper, we model the service provisioning problem as a generalized Nash game and we show the existence of equilibria for such game. Moreover, we propose two solution methods based on the best-reply dynamics, and we prove their convergence in a finite number of iterations to a generalized Nash equilibrium. In particular, we develop an efficient distributed algorithm for the runtime allocation of IaaS resources among competing SaaS providers. We demonstrate the effectiveness of our approach by simulation and performing tests on a real prototype environment deployed on Amazon EC2. Results show that, compared to other state-of-the-art solutions, our model can improve the efficiency of the cloud system evaluated in terms of Price of Anarchy by 50-70 percent.