The production of the prompt charmed mesons D 0 , D + , and D * + relative to the reaction plane was measured in Pb-Pb collisions at a center-of-mass energy per nucleon-nucleon collision of √ s NN = 2.76 TeV with the ALICE detector at the CERN Large Hadron Collider. D mesons were reconstructed via their hadronic decays at central rapidity in the transverse-momentum (p T ) interval 2-16 GeV/c. The azimuthal anisotropy is quantified in terms of the second coefficient v 2 in a Fourier expansion of the D-meson azimuthal distribution and in terms of the nuclear modification factor R AA , measured in the direction of the reaction plane and orthogonal to it. The v 2 coefficient was measured with three different methods and in three centrality classes in the interval 0%-50%. A positive v 2 is observed in midcentral collisions (30%-50% centrality class), with a mean value of 0.204 +0.099 −0.036 (tot. unc.) in the interval 2 < p T < 6 GeV/c, which decreases towards more central collisions (10%-30% and 0%-10% classes). The positive v 2 is also reflected in the nuclear modification factor, which shows a stronger suppression in the direction orthogonal to the reaction plane for midcentral collisions. The measurements are compared to theoretical calculations of charm-quark transport and energy loss in high-density strongly interacting matter at high temperature. The models that include substantial elastic interactions with an expanding medium provide a good description of the observed anisotropy. However, they are challenged to simultaneously describe the strong suppression of high-p T yield of D mesons in central collisions and their azimuthal anisotropy in noncentral collisions.