We use cosmological simulations to study the origin of primordial star-forming clouds in a ÃCDM universe, by following the formation of dark matter halos and the cooling of gas within them. To model the physics of chemically pristine gas, we employ a nonequilibrium treatment of the chemistry of nine species (e À , H, H + , He, He + , He ++ , H 2 , H þ 2 , H À ) and include cooling by molecular hydrogen. By considering cosmological volumes, we are able to study the statistical properties of primordial halos, and the high resolution of our simulations enables us to examine these objects in detail. In particular, we explore the hierarchical growth of bound structures forming at redshifts z % 25 30 with total masses in the range %10 5 10 6 M . We find that when the amount of molecular hydrogen in these objects reaches a critical level, cooling by rotational line emission is efficient, and dense clumps of cold gas form. We identify these '' gas clouds '' as sites for primordial star formation. In our simulations, the threshold for gas cloud formation by molecular cooling corresponds to a critical halo mass of %5 Â 10 5 h À1 M , in agreement with earlier estimates, but with a weak dependence on redshift in the range z > 16. The complex interplay between the gravitational formation of dark halos and the thermodynamic and chemical evolution of the gas clouds compromises analytic estimates of the critical H 2 fraction. Dynamical heating from mass accretion and mergers opposes relatively inefficient cooling by molecular hydrogen, delaying the production of star-forming clouds in rapidly growing halos. We also investigate the effect of photodissociating ultraviolet radiation on the formation of primordial gas clouds. We consider two extreme cases, first by including a uniform radiation field in the optically thin limit and second by accounting for the maximum effect of gas self-shielding in virialized regions. For radiation with Lyman-Werner band flux J > 10 À23 ergs s À1 cm À2 Hz À1 sr À1 , hydrogen molecules are rapidly dissociated, rendering gas cooling inefficient. In both the cases we consider, the overall effect can be described by computing an equilibrium H 2 abundance for the radiation flux and defining an effective shielding factor. Based on our numerical results, we develop a semianalytic model of the formation of the first stars and demonstrate how it can be coupled with large N-body simulations to predict the star formation rate in the early universe.