Virgil acts as Dante's guide on his journey through hell to find spiritual enlightenment. Virgil is a fitting guide for Dante as Dante admired Virgil's work and considered him to be the most sublime poet of all earlier poets. He aspired to write like Virgil and considered him to be the perfect example after which to model himself and his works.
Virgil is able to accompany Dante through hell in which he warns him he will see many frightening, disturbing things. Virgil, however, is unable to guide Dante past purgatory becuase he was a pagan -- he lived before the time of Christ and worshiped the gods of mythology. Because he didn't develop a personal relationship with Christ as savior, he is unable to dwell in heaven.