Energy systems based on renewables have an increasing demand for flexibility. In this paper, we consider the potential of power-to-gas to provide flexibility and enhance the system integration of renewables. Existing research on power-to-gas typically analyses the system effects of a predetermined power-to-gas unit without endogenising the investment decision. Moreover, insights related to the market and portfolio effects of power-to-gas are rare. To this end we present a stochastic mixed complementarity problem, which models the optimisation problems of different market players individually. The players we consider include power generating firms with different generation portfolios and different consumer groups. Firms earn revenues from an energy market, a quantity-based capacity market and a feed-in premium for renewable generation. They maximise their profits by optimising the operation of existing assets and making investments in new generation assets and in power-to-gas. We find that firms with renewable generation benefit from investing in power-to-gas. While the technology itself is loss-making, power-to-gas particularly increases demand and hence prices in low-load hours. Therefore, renewable generation becomes more profitable, which justifies the investment. However, the price increase results in higher costs to consumers so the overall transfer from consumers to wind generators increases in the presence of power-to-gas.