Recently, an anomalous excess was found in the electronic recoil data collected at the XENON1T experiment. The excess may be explained by an axionlike particle (ALP) with a mass of a few keV and a coupling to electron of gae~10-13, if the ALP constitutes all or some fraction of local dark matter (DM). In order to satisfy the x-ray constraint, the ALP coupling to photons must be significantly suppressed compared to that to electrons. This strongly suggests that the ALP has no anomalous couplings to photons; i.e., there is no U(1)PQ-U(1)em-U(1)em anomaly. We show that such anomaly-free ALP DM predicts an x-ray line signal with a definite strength through the operator arising from threshold corrections, and compare it with the projected sensitivity of the ATHENA x-ray observatory. The abundance of ALP DM can be explained by the misalignment mechanism, or by thermal production if it constitutes a part of DM. In particular, we find that the anomalous excess reported by the XENON1T experiment as well as the stellar cooling anomalies from white dwarfs and red giants can be explained simultaneously better when the ALP constitutes about 10% of DM. As concrete models, we revisit the leptophilic anomaly-free ALP DM considered in K. Nakayama, F. Takahashi, and T. T. Yanagida [Phys. Lett. B 734, 178 (2014)] as well as an ALP model based on a two Higgs doublet model in the Supplemental Material.