If a fluctuating medium is confined, the ensuing perturbation of its fluctuation spectrum generates Casimir-like effective forces acting on its confining surfaces. Near a continuous phase transition of such a medium the corresponding order parameter fluctuations occur on all length scales and therefore close to the critical point this effect acquires a universal character, i.e., to a large extent it is independent of the microscopic details of the actual system. Accordingly it can be calculated theoretically by studying suitable representative model systems. We report on the direct measurement of critical Casimir forces by total internal reflection microscopy with femtonewton resolution. The corresponding potentials are determined for individual colloidal particles floating above a substrate under the action of the critical thermal noise in the solvent medium, constituted by a binary liquid mixture of water and 2,6-lutidine near its lower consolute point. Depending on the relative adsorption preferences of the colloid and substrate surfaces with respect to the two components of the binary liquid mixture, we observe that, upon approaching the critical point of the solvent, attractive or repulsive forces emerge and supersede those prevailing away from it. Based on the knowledge of the critical Casimir forces acting in film geometries within the Ising universality class and with equal or opposing boundary conditions, we provide the corresponding theoretical predictions for the sphere-planar wall geometry of the experiment. The experimental data for the effective potential can be interpreted consistently in terms of these predictions and a remarkable quantitative agreement is observed.