A ferroelectric is a material with a polar structure whose polarity can be reversed by applying an electric field. In metals, the itinerant electrons tend to screen electrostatic forces between ions, helping to explain why polar metals are very rare. Screening also excludes external electric fields, apparently ruling out the possibility of polarity reversal and thus ferroelectric switching. In principle, however, a thin enough polar metal could be penetrated by an electric field sufficiently to be switched. Here we show that the layered topological semimetal WTe2 provides the first embodiment of this principle. Although monolayer WTe2 is centrosymmetric and thus nonpolar, the stacked bulk structure is polar. We find that two- or three-layer WTe2 exhibits a spontaneous out-of-plane electric polarization which can be switched using gate electrodes. We directly detect and quantify the polarization using graphene as an electric field sensor. Moreover, the polarization states can be differentiated by conductivity, and the carrier density can be varied to modify the properties. The critical temperature is above 350 K, and even when WTe2 is sandwiched in graphene it retains its switching capability at room temperature, demonstrating a robustness suitable for applications in combination with other two-dimensional materials.