There are two mechanisms that produce genetic change in multicellular organisms: the shuffling of genes that occurs in sexual reproduction, with the chromosomes of the parents being combined in new ways, and random genetic mutation resulting from replication errors or exposure to radiation or toxins. As a result of these mechanisms, different individuals in a population will have slight differences from one another. If those differences increase their ability to survive in their environment, then they will have more offspring, and their offspring will have more offspring, and so on. While those individuals whose genes make them less suited to their environment will have fewer offspring. So over time, the traits that improve survival and reproductive success will spread through the population until the whole species has them. (For instance, if a species of animal eats fruit and leaves from tall trees, then taller or longer-necked ones will get more food and have more babies, so eventually the whole species gets really tall. That's how giraffes happened.)
So the main mechanism behind evolution is adaptation to one's environment. But then how does a species develop a totally new attribute allowing them to move into a new environment, like fish moving onto land? Partly by adapting existing traits for different purposes. Fish have air-filled bladders that they use for buoyancy. Some fish that lived near the shoreline were able to escape from predatory sea creatures, it's believed, by swimming as close to the shore as possible, maybe even jumping out of the water altogether and struggling to get back once the danger was past. Eventually, a mutation allowed one fish and its offspring to take air from their flotation bladders into their bloodstream and survive off of that until they could get back into the water. They were therefore better at escaping predators than fish that couldn't do this, so more of them survived and had more offspring. Further mutations along the way gradually improved their ability to survive off air in their flotation bladders, so that those bladders gradually evolved into lungs.
Naturally, at first they were just dragging themselves along the ground with their fins. But mutations and reproductive mixing make anatomical change inevitable, and some random changes happen to give a survival advantage. In this case, some lungfish were born with slightly longer, stronger, stiffer fins and were able to drag themselves along better. And then some of their descendants had even longer, stronger fins, and so on, and so on, until eventually they had legs.
One aspect of this that's recently been discovered: once a species enters a new niche like that, its evolution can go faster. Why? Because as it dominates a new niche, its population grows. That means there are more genetic combinations being tried out, so beneficial changes come along more frequently, accelerating the pace at which the species adapts. For instance, genetic studies have shown that human evolution has accelerated greatly in the past 40,000 years as our population has grown. Nothing huge, but subtle adaptations like our metabolisms and teeth and digestive systems becoming better adapted to our changing diet as we developed agriculture and herding. There are just so many more of us that beneficial changes crop up more often.
So this process can accelerate a species' adaptation to a new environment, a new way of living. Of course we're still talking on the scale of hundreds or thousands of generations, because these are very gradual changes, but it does apparently help things along significantly.