Competent public agencies are associated with better economic outcomes. Beyond competence, political leaders need to secure the loyalty of their agencies. Unfortunately, several theories predict a tradeoff between these two valued features. This paper finds that recruitment into agencies is meritocratic where (1) agency officials have poor outside options, (2) careers in agencies are long-lasting, and (3) agency loyalty is important. Moreover, agency competence is lower when (4) loyalty is important but the time horizon is short, and (5) outside opportunities improve but the time horizon is long. This evidence fits best with a theory of loyalty as non-contractible behavior.