We present a numerical technique for calculating path integrals in non-compact U(1) and SU(2) gauge theories. The gauge fields are represented by a superposition of pseudoparticles of various types with their amplitudes and color orientations as degrees of freedom. Applied to Maxwell theory this technique results in a potential which is in excellent agreement with the Coulomb potential. For SU(2) Yang-Mills theory the same technique yields clear evidence of confinement. Varying the coupling constant exhibits the same scaling behavior for the string tension, the topological susceptibility and the critical temperature while their dimensionless ratios are similar to those obtained in lattice calculations.