We analyze the one-dimensional electoral competition between two parties when the ideology of each party is endogenously determined. The parties are composed of two factions: the 'opportunists' and the 'militants'. The ideology of each party is determined by the preferences of the median citizen supporting the party. Under the proportional system, where parties are represented proportionally to the share of their votes, we first study the short-term political equilibria. We then introduce a dynamic setup that endogenizes the composition of the parties, in order to analyze the stability of these equilibria. We make explicit the stability conditions for the two equilibria where all the opportunists belong to the same party and for the unique equilibrium where they are distributed between both parties. The conditions involve the rates of party switching and of ideological adjustment. This coupled adjustment process makes it possible for party competition to sustain proportional representation, fluctuation in party positioning, and some degree of policy divergence.