We analyze how political discretion affects the selection of government workers, using individual-level data on political party membership and matched employer-employee data on the universe of formal workers in Brazil. Exploiting close mayoral races, we find that winning an election leads to an increase of over 40% in the number of members of the winning party working in the municipal bureaucracy. Employment of members of the ruling party increases relatively more in senior positions, but also expands in lower-ranked jobs, suggesting that discretionary appointments are used both to influence policymaking and to reward supporters. We find that party members hired after their party is elected tend be of similar or even higher quality than members of the runner-up party, contrary to common perceptions that political appointees are less qualified. Moreover, the increased public employment of members of the ruling party is long-lasting, extending beyond the end of the mayoral term.JEL Classification: D72, D73, H70, J45