In this paper a multiband envelope-function Hamiltonian for lattice-matched semiconductor heterostructures is derived from first-principles self-consistent norm-conserving pseudopotentials. The theory is applicable to isovalent or heterovalent heterostructures with macroscopically neutral interfaces and no spontaneous bulk polarization. The key assumption-proved in earlier numerical studies-is that the heterostructure can be treated as a weak perturbation with respect to some periodic reference crystal, with the nonlinear response small in comparison to the linear response. Quadratic response theory is then used in conjunction with k · p perturbation theory to develop a multiband effective-mass Hamiltonian ͑for slowly varying envelope functions͒ in which all interface band-mixing effects are determined by the linear response. To within terms of the same order as the position dependence of the effective mass, the quadratic response contributes only a bulk band offset term and an interface dipole term, both of which are diagonal in the effective-mass Hamiltonian. The interface band mixing is therefore described by a set of bulklike parameters modulated by a structure factor that determines the distribution of atoms in the heterostructure. The same linear parameters determine the interface band-mixing Hamiltonian for slowly varying and ͑sufficiently large͒ abrupt heterostructures of arbitrary shape and orientation. Long-range multipole Coulomb fields arise in quantum wires or dots, but have no qualitative effect in two-dimensional systems beyond a dipole contribution to the band offsets. The method of invariants is used to determine the explicit form of the Hamiltonian for ⌫ 6 and ⌫ 8 states in semiconductors with the zinc-blende structure, and for intervalley mixing of ⌫ and X electrons in ͑001͒ GaAs/ AlAs heterostructures.