Abstract. Introduced in the late 1960's [33,43], the asymmetric exclusion process (ASEP) is an important model from statistical mechanics which describes a system of interacting particles hopping left and right on a one-dimensional lattice of n sites. It has been cited as a model for traffic flow and protein synthesis. In the most general form of the ASEP with open boundaries, particles may enter and exit at the left with probabilities α and γ, and they may exit and enter at the right with probabilities β and δ. In the bulk, the probability of hopping left is q times the probability of hopping right. The first main result of this paper is a combinatorial formula for the stationary distribution of the ASEP with all parameters general, in terms of a new class of tableaux which we call staircase tableaux. This generalizes our previous work [14,15] for the ASEP with parameters γ = δ = 0. Using our first result and also results of Uchiyama-Sasamoto-Wadati [48], we derive our second main result: a combinatorial formula for the moments of Askey-Wilson polynomials. Since the early 1980's there has been a great deal of work giving combinatorial formulas for moments of various other classical orthogonal polynomials (e.g. Hermite, Charlier, Laguerre, Meixner). However, this is the first such formula for the Askey-Wilson polynomials, which are at the top of the hierarchy of classical orthogonal polynomials.