The Three-eyed Raven is an ancient human greenseer (someone able to use greensight, which is the prophetic ability Bran has). How he came to be under the weirwood tree remains a mystery, but he tells Bran that he has been there for 1,000 years -
Three-eyed Raven: You think I wanted to sit here for 1,000 years watching the world from a distance as the roots grew through me?
Bran: So why did you?
Three-eyed Raven: I was waiting for you.
Before meeting the Three-eyed Raven, Bran experiences greensight dreams but is unable to trigger the ability at will. Touching the roots of the weirdwood allows him to use greensight, indicating that the roots running through the Three-eyed Raven have special powers. This appears to be why the Three-eyed Raven is there, drawing from the power of the weirwood to use greensight and have unnaturally long life.
Bran is not literally the same as the Three-eyed Raven, but rather his replacement. This is why the Three-Eyed Raven drew Bran to him and attempted to teach him to master greensight. Unfortunately, Bran instead misuses it and lures the Night King to the cave. After the Three-eyed Raven is killed, Benjen Stark remarks on his passing:
Meera: Why did you help us?
Benjen: The Three-Eyed Raven sent for me.
Meera: The Three-Eyed Raven's dead.
Benjen: Now he lives again.
This implies that Three-eyed Raven is a title and Bran is the new Three-eyed Raven. It is yet to be revealed what his exact purpose is.