The general mechanism by which the irregular moons of the giant planets were captured is thought first to have involved temporary gravitational trapping within the planet's Hill sphere (a region where planetary gravity dominates solar tides) followed by dissipative energy loss (or planetary growth) to make capture permanent. However, the orbital inclination distributions of recently discovered irregular moons cannot be adequately explained using existing theories. We argue that irregular moons were captured by first getting entangled in a thin layer of chaos inside the Hill sphere. With increasing energy this chaotic layer evolves smoothly from prograde to retrograde motion. Permanent capture happens as dissipation switches long-living chaotic orbits into nearby regular (non-chaotic) zones; hence the chaotic layer largely dictates the final inclinations of captured moons. This is confirmed by three-dimensional Monte Carlo simulations which include dissipation in the form of nebular drag. Good agreement with observed inclination distributions of irregular moons at Jupiter and Saturn is found. A possible explanation is presented for the apparent primordial propensity of Saturn to capture a larger fraction of prograde moons than Jupiter. Application to the formation of binaries in the Kuiper-belt is discussed