We study a game-theoretic model where three political parties (left, median and right) can form coalitions both before and after the election. Before the election, coalitions can commit to a seat-sharing arrangement, but not to a policy platform or a division of rents from office; coalition members are free to break up and join other coalitions after the election. Equilibrium pre-electoral coalitions are not necessarily made up of the most ideologically similar parties, and they form under proportional representation as well as plurality rule. They form not only to avoid splitting the vote, but also because seat-sharing arrangements will influence the post-election bargaining and coalition formation. The median party's share of the surplus in a two-party government is large if ideology is not very important, or if its ideological position is not very distant from the third (outside) party, so that it has a credible threat to switch coalition partners. On the other hand, if ideology is very important, and if the right and left parties are ideologically distant from each other so each is willing to give up a lot to prevent the other from joining a governing coalition, then the equilibrium outcome may be that the median party forms a one-party government.