The Crab pulsar is a typical example of a young, rapidly spinning, strongly magnetized neutron star that generates broad-band electromagnetic radiation by accelerating charged particles to near light speeds in its magnetosphere(1). Details of this emission process so far remain poorly understood. Measurement of polarization in X-rays, particularly as a function of pulse phase, is thought to be a key element necessary to unravel the mystery of pulsar radiation(2-4). Such measurements are extremely difficult, however: to date, Crab is the only pulsar to have been detected in polarized X-rays(5-8) and the measurements have not been sensitive enough to adequately reveal the variation of polarization characteristics across the pulse(7). Here, we present the most sensitive measurement to date of polarized hard X-ray emission from the Crab pulsar and nebula in the 100-380 keV band, using the Cadmium-Zinc-Telluride Imager(9) instrument on-board the Indian astronomy satellite AstroSat(10). We confirm with high significance the earlier indication(6,7) of a strongly polarized off-pulse emission. However, we also find a variation in polarization properties within the off-pulse region. In addition, our data hint at a swing of the polarization angle across the pulse peaks. This behaviour cannot be fully explained by the existing theoretical models of high-energy emission from pulsars.