  The central engine that powers gamma-ray bursts (GRBs), the most powerful
explosions in the universe, is still not identified. Besides hyper-accreting
black holes, rapidly spinning and highly magnetized neutron stars, known as
millisecond magnetars, have been suggested to power both long and short GRBs.
The presence of a magnetar engine following compact star mergers is of
particular interest as it would provide essential constraints on the poorly
understood equation of state for neutron stars. Indirect indications of a
magnetar engine in these merger sources have been observed in the form of
plateau features present in the X-ray afterglow light curves of some short
GRBs. Additionally, some X-ray transients lacking gamma-ray bursts (GRB-less)
have been identified as potential magnetar candidates originating from compact
star mergers. Nevertheless, smoking gun evidence is still lacking for a
magnetar engine in short GRBs, and the associated theoretical challenges have
been addressed. Here we present a comprehensive analysis of the broad-band
prompt emission data of a peculiar, very bright GRB 230307A. Despite its
apparently long duration, the prompt emission and host galaxy properties point
toward a compact star merger origin, being consistent with its association with
a kilonova. More intriguingly, an extended X-ray emission component emerges as
the $\gamma$-ray emission dies out, signifying the emergence of a magnetar
central engine. We also identify an achromatic temporal break in the
high-energy band during the prompt emission phase, which was never observed in
previous bursts and reveals a narrow jet with half opening angle of
approximately $3.4^\circ$.
