Current experiments on atomic gases in highly anisotropic traps present the opportunity to study in detail the low temperature phases of two-dimensional inhomogeneous systems. Although, in an ideal gas, the trapping potential favors Bose-Einstein condensation at finite temperature, interactions tend to destabilize the condensate, leading to a superfluid Kosterlitz-Thouless-Berezinskii phase with a finite superfluid mass density but no long-range order, as in homogeneous fluids. The transition in homogeneous systems is conveniently described in terms of dissociation of topological defects (vortex-antivortex pairs). However, trapped two-dimensional gases are more directly approached by generalizing the microscopic theory of the homogeneous gas. In this paper, we first derive, via a diagrammatic expansion, the scaling structure near the phase transition in a homogeneous system, and then study the effects of a trapping potential in the local density approximation. We find that a weakly interacting trapped gas undergoes a Kosterlitz-Thouless-Berezinskii transition from the normal state at a temperature slightly below the Bose-Einstein transition temperature of the ideal gas. The characteristic finite superfluid mass density of a homogeneous system just below the transition becomes strongly suppressed in a trapped gas.two dimensions ͉ phase transitions ͉ trapped atoms T he ability to produce two-dimensional atomic gases trapped in optical potentials has stimulated considerable interest in the Kosterlitz-Thouless-Berezinskii (KTB) transition in such systems (1-7); recently, the transition has been observed in a quasi two-dimensional system of trapped rubidium atoms (8, 9). A homogeneous Bose gas in two dimensions undergoes BoseEinstein condensation (BEC) only at zero temperature, since long wavelength phase fluctuations destroy long range order (10-13); nonetheless, interparticle interactions drive a phase transition to a superfluid state at finite temperature, as first pointed out by Berezinskii (14,15) and by Kosterlitz and Thouless (16,17). The phase transition is characterized by an algebraic decay of the off-diagonal one-body density matrix (or single particle Green's function) in real space below the transition temperature, T KT . Furthermore, the superfluid mass density, s , jumps with falling temperature, T, from 0 just above T KT to a universal value s ϭ 2m 2 T KT ͞ just below (18), where m is the atomic mass. (We use units ϭ k B ϭ 1.)A noninteracting homogeneous Bose gas in two dimensions does not undergo Bose-Einstein condensation at finite temperature. In such a system, the density is given in terms of the chemical potential bywhere  ϭ 1͞T, and ϭ (2 ͞mT) 1/2 is the thermal wavelength.As approaches zero at fixed temperature, the density grows arbitrarily, implying the absence of condensation. On the other hand, a trapped noninteracting gas does undergo a BoseEinstein condensation at a finite temperature (19). In the semiclassical limit, the total number of particles is given by N( ) ϭ g 2 (Ϫ )(T͞ ) 2 , w...