I present a fully-rational symmetric-information model of an IPO, and a dynamic imperfectly competitive model of trading in the IPO aftermarket. The model helps to explain IPO underpricing, underperformance, and why share allocations favor large institutional investors. In the model, underwriters need to sell a fixed number of shares at the IPO or in the aftermarket. To maximize revenue and avoid selling into the aftermarket where they can be exploited by large investors, underwriters distort share allocations towards investors with market power, and set the IPO offer price below the aftermarket trading price. Large investors who receive IPO share allocations sell them slowly afterwards to reduce their trade's price-impact. This curtails the shares that are available to small price-taking investors, causing them to bid up prices and bid down returns. In some simulations, the distorted share allocations and slow unwinding behavior generate post-IPO return underperformance that persists for several years.