Swarming, or aggregations of organisms in groups, can be found in nature in many organisms ranging from simple bacteria to mammals. Such behavior can result from several different mechanisms. For example, individuals may respond directly to local physical cues such as concentration of nutrients or distribution of some chemicals as seen in some bacteria and social insects, or they may respond directly to other individuals as seen in fish, birds, and herds of mammals. In this dissertation, we consider models for aggregating and social foraging swarms and perform rigorous stability analysis of emerging collective behavior. Moreover, we consider formation control of a general class of multi-agent systems in the framework of nonlinear output regulation problem with application on formation control of mobile robots. First, an individual-based continuous time model for swarm aggregation in an n-dimensional space is identified and its stability properties are analyzed. The motion of each individual is determined by two factors: (i) attraction to the other individuals on long distances and (ii) repulsion from the other individuals on short distances. It is shown that the individuals (autonomous agents or biological creatures) will form a cohesive swarm in a finite time. Moreover, explicit bounds on the swarm size and time of convergence are derived. Then, the results are generalized to a more general class of attraction/repulsion functions and extended to handle formation stabilization and uniform swarm density. After that, we consider social foraging swarms. We assume that the swarm is moving in an environment with an "attractant/repellent" profile (i.e., a profile of nutrients or toxic substances) which also affects the motion of each individual by an attraction to the more favorable or nutrient rich regions (or repulsion from the unfavorable or toxic regions) of the profile. The stability properties of the collective behavior of the swarm for different profiles are studied and conditions for collective convergence to more favorable regions are provided. Then, we use the ideas for modeling and analyzing the behavior of honey bee clusters and in-transit swarms, a phenomena seen during the reproduction of the bees. After that, we consider one-dimensional asynchronous swarms with time delays. We prove that, despite the asynchronism and time delays in the motion of the individuals, the swarm will converge to a comfortable position with comfortable intermember spacing. Finally, we consider formation control of a multi-agent system with general nonlinear dynamics. It is assumed that the formation is required to follow a virtual leader whose dynamics are generated by an autonomous neutrally stable system. We develop a decentralized control strategy based on the nonlinear output regulation (servomechanism) theory. We illustrate the procedure with application to formation control of mobile robots.