We develop a model of intraparty candidate selection under partisan electoral competition and voter uncertainty. Candidates for office belong to parties, which are factions of ideologically similar candidates. Each party’s candidate for a general election can be selected either by a “centralized” mechanism that effectively randomizes over possible candidates or by voters in a primary election. The electorate cares about ideology and valence, and both primary and general elections may reveal candidate valences. Our main theoretical result is that while primaries raise the expected quality of a party’s candidates, they may hurt the ex ante preferred party in a competitive electorate by increasing the chances of revealing the opposing party’s candidates as superior. Thus, primaries are adopted in relatively extreme districts where a clear favorite party exists. An empirical analysis of the adoption of direct primaries and the competitiveness of primary elections across U.S. states supports these predictions.