We construct the microstates of near-extremal black holes in AdS_5 x S^5 as gases of defects distributed in heavy BPS operators in the dual SU(N) Yang-Mills theory. These defects describe open strings on spherical D3-branes in the S^5, and we show that they dominate the entropy by directly enumerating them and comparing the results with a partition sum calculation. We display new decoupling limits in which the field theory of the lightest open strings on the D-branes becomes dual to a near-horizon region of the black hole geometry. In the single-charge black hole we find evidence for an infrared duality between SU(N) Yang-Mills theories that exchanges the rank of the gauge group with an R-charge. In the two-charge case (where pairs of branes intersect on a line), the decoupled geometry includes an AdS_3 factor with a two-dimensional CFT dual. The degeneracy in this CFT accounts for the black hole entropy. In the three-charge case (where triples of branes intersect at a point), the decoupled geometry contains an AdS_2 factor. Below a certain critical mass, the two-charge system displays solutions with naked timelike singularities even though they do not violate a BPS bound. We suggest a string theoretic resolution of these singularities.