Energybending is the ability to bend life energy. It predates the main four bending arts, as well as the arrival of the Avatar and the formation of the Four Nations.
Before the arrival of the Avatar into the world, and the separation of the four elements, people bent the energy within themselves. They discovered the other four bending arts, and over time knowledge of Energybending was almost completely lost. The last known keeper of the art was an ancient Lion Turtle, who later passed it down to Avatar Aang, who used it to remove Ozai's Firebending forever.
The capabilities of Energybending are not well understood; what is known is that bending a person's life energy can impart them with knowledge instantly or remove one's bending completely. This bending art is dissimilar to the others because it is so perilous to the user, which is why so few have ever used it.
After discovering that the mysterious island on which he consulted his past lives was in fact a Lion Turtle, Aang sought the advice of the ancient creature, on what he should do about Ozai, as Aang couldn't bear the thought of killing someone. He asks for wisdom on how to stop the Fire Lord without taking his life.
The Lion Turtle answered, "The true mind can weather all the lies and illusions without being lost. The true heart can touch the poison of hatred without being harmed. Since beginning-less time, darkness thrives in the void, but always yields to purifying light". The Lion-Turtle brought up a paw, his two claws touching Aang's chest and forehead, causing a green light to illuminate. It is likely that the Lion Turtle used Energybending himself to impart the knowledge of the art to Aang.
Aang didn't understand at first, but was comforted by this wisdom. During the battle with Ozai, Aang was in the Avatar State, and with the combined powers of the past Avatars and all four elements, the Avatar was ready to deal the final blow. At the last second, Aang regains control and exits from the Avatar State, hoping not to end the Fire Lord's life. Ozai mocked that even though he has all the power in the world, he is still weak and attempted to attack Aang, who sensed the attack with Earthbending, and pins Ozai down again. In this moment, he realizes the meaning of the advice of the Lion Turtle, and he decides to act on it.
The Lion Turtle told him that in the era before the Avatar existed, the benders did not bend the elements, but the energy within themselves. In order to bend another's life energy, their own spirit must be un-bendable, or they would be corrupted and destroyed.
It is Aang's "true heart" and "true mind", tested in the heat of battle at the moment of striking down Ozai, that allowed him to harness the wisdom of the Lion Turtle and successfully Energybend Ozai.
As this was happening, Aang's entire body was glowing white and blue, while Ozai's body shined orange and red, showing that life energy itself. At first Aang's spirit was nearly enveloped by Ozai, but at the last moment, his spirit took over and covered Ozai, removing his firebending. This was Aang's revelation; if he truly believed he had no right to take life, he would have to risk his own to defeat his enemy without killing him. In doing so, he was able to remain true to his beliefs, and secured his final victory over the Fire Nation.
Energybending is an extremely powerful and potentially dangerous technique. If the bender's spirit is even slightly weak (bendable), then they will be infected by the spirit of the one they are bending. As a result, the bender can be corrupted and even killed.