Agahnim was a wandering wizard who assisted the Royal Family at a time when Hyrule was plagued by flood, famine and disease. Agahnim played the role of trusted advisor for a time, but soon he displayed his true colors and seized power for himself. After imprisoning the Seven Sages and Princess Zelda, Agahnim used his magic to break the seal which imprisoned Ganon in the Dark World. Agahnim was defeated by his own dark magic thanks to Link's quick thinking.
In Link's Awakening, Agahnim's Shadow was one of the Shadows of Link's former foes that attacked Link in the final battle in Koholint Island's Wind Fish Egg.
Source: Wikipedia, "Characters in The Legend of Zelda series," available under the CC-BY-SA License.