The feedback between fluid migration and rock deformation in mid-crustal shear zones is acknowledged as being critical for earthquake nucleation, the initiation of subduction zones and the formation of mineral deposits. The importance of this poorly understood feedback is further highlighted by evidence for shear-zone-controlled advective flow of fluids in the ductile lower crust4 and the recognition that deformation-induced grain-scale porosity is a key to large-scale geodynamics. Fluid migration in the middle crust cannot be explained in terms of classical concepts. The environment is considered too hot for a dynamic fracture-sustained permeability as in the upper crust, and fluid pathways are generally too deformed to be controlled by equilibrium wetting angles that apply to hotter, deeper environments. Here we present evidence that mechanical and chemical potentials control a syndeformational porosity generation in mid-crustal shear zones. High-resolution synchrotron X-ray tomography and scanning electron microscopy observations allow us to formulate a model for fluid migration in shear zones where a permeable porosity is dynamically created by viscous grain-boundary sliding, creep cavitation, dissolution and precipitation. We propose that syndeformational fluid migration in our 'granular fluid pump' model is a self-sustained process controlled by the explicit role of the rate of entropy production of the underlying irreversible mechanical and chemical microprocesses. The model explains fluid transfer through the middle crust, where strain localization in the creep regime is required for plate tectonics, the formation of giant ore deposits, mantle degassing and earthquake nucleation. Our findings provide a key component for the understanding of creep instabilities in the middle crust.