  We show that an axionlike particle (ALP) naturally implements spontaneous
electroweak baryogenesis through a cosmic evolution strongly tied to the
electroweak phase transition (EWPT) if it feebly couples to the Higgs field
while giving a small contribution to the Higgs boson mass. The observed baryon
asymmetry can be generated successfully if the ALP couples strongly enough to
the electroweak anomaly. Also interesting is that the ALP contributes to dark
matter, and its coupling to a hidden gauge sector makes the relic abundance
insensitive to the cosmic history before the EWPT. The ALP explains both the
baryon asymmetry and dark matter in a wide range of the couplings owing to the
friction induced by the hidden gauge sector. To be compatible with cosmological
and astrophysical observations, the ALP should have a mass in the range between
about 0.01 and 30 eV, and is further required to be photophobic if its coupling
to the electroweak anomaly is strong, constraining the field content and charge
assignment of the UV completion.
