Asteroids are believed to have originated during the formation of the Solar System, when planetesimals accreted from solar nebula. The more primitive carbonaceous asteroids may have evolved little since then, while the other types may have been parts of larger bodies that first accreted and later broke up by collisions.
Recently a few small asteroids have been discovered in highly elliptical orbits that come inside the orbit of Mars, some crossing the orbit of the Earth - the Apollo, Amor, and Aten families.