We present a two-dimensional (2-D) fitting algorithm (GALFIT) designed to extract structural components from galaxy images, with emphasis on closely modeling light profiles of spatially well-resolved, nearby galaxies observed with the Hubble Space Telescope. Our algorithm improves on previous techniques in two areas, by being able to simultaneously fit a galaxy with an arbitrary number of components, and with optimization in computation speed, suited for working on large galaxy images. We use 2-D models such as the ``Nuker law, the Sersic (de Vaucouleurs) profile, an exponential disk, and Gaussian or Moffat functions. The azimuthal shapes are generalized ellipses that can fit disky and boxy components. Many galaxies with complex isophotes, ellipticity changes, and position-angle twists can be modeled accurately in 2-D. When examined in detail, we find that even simple-looking galaxies generally require at least three components to be modeled accurately, rather than the one or two components more often employed. We illustrate this by way of 7 case studies, which include regular and barred spiral galaxies, highly disky lenticular galaxies, and elliptical galaxies displaying various levels of complexities. A useful extension of this algorithm is to accurately extract nuclear point sources in galaxies. We compare 2-D and 1-D extraction techniques on simulated images of galaxies having nuclear slopes with different degrees of cuspiness, and we then illustrate the application of the program to several examples of nearby galaxies with weak nuclei.