We use Drinfeld's relative compactifications and the Tannakian viewpoint on principal bundles to construct the Harder-Narasimhan stratification of the moduli stack Bun_G of G-bundles on an algebraic curve in arbitrary characteristic, generalizing the stratification for G=GL_n due to Harder and Narasimhan to the case of an arbitrary reductive group G. To establish the stratification on the set-theoretic level, we exploit a Tannakian interpretation of the Bruhat decomposition and give a new and purely geometric proof of the existence and uniqueness of the canonical reduction in arbitrary characteristic. We furthermore provide a Tannakian interpretation of the canonical reduction in characteristic 0 which allows to study its behavior in families. The substack structures on the strata are defined directly in terms of Drinfeld's compactifications, which we generalize to the case where the derived group of G is not necessarily simply connected. We furthermore use Drinfeld's compactifications to establish various properties of the stratification, including finer information about the structure of the individual strata and a simple description of the strata closures. Finally, we introduce a novel notion of slope for principal bundles which allows for a natural formulation of the reduction theory of arbitrary reductive groups in arbitrary characteristic.