For (3+1)-dimensional fermions, a net axial charge and external magnetic field can lead to a current parallel to the magnetic field. This is the chiral magnetic effect. We use gauge-gravity duality to study the chiral magnetic effect in large-Nc, strongly-coupled N=4 supersymmetric SU(Nc) Yang-Mills theory coupled to a number Nf << Nc of N=2 hypermultiplets in the Nc representation of SU(Nc), i.e. flavor fields. Specifically, we introduce an external magnetic field and a time-dependent phase for the mass of the flavor fields, which is equivalent to an axial chemical potential for the flavor fermions, and we compute holographically the resulting chiral magnetic current. For massless flavors we find that the current takes the value determined by the axial anomaly. For massive flavors the current appears only in the presence of a condensate of pseudo-scalar mesons, and has a smaller value than for massless flavors, dropping to zero for sufficiently large mass or magnetic field. The axial symmetry in our system is part of the R-symmetry, and the states we study involve a net flow of axial charge to the adjoint sector from an external source coupled to the flavors. We compute the time rate of change of axial charge and of energy both in field theory and from holography, with perfect agreement. In contrast to previous holographic models of the chiral magnetic effect, in our system the vector current is conserved and gauge-invariant without any special counterterms.