The idea of Aeneas being the founder of Rome predates Virgil by many centuries. In fact, Rome is not the only place which claimed to have been founded by Aeneas. As early as the sixth century BC Aeneia in Macedonia was issuing coins showing Aeneas carrying his father from Troy.
But there was an idea that Aeneas fled farther west. The Sicilian poet Stesichorus in about 550 BC may have contributed to this idea. By the end of the fifth century the Greek historians Hellanicus of Lesbos and Damastes of Sigeum both referred to Rome as being founded by Aeneas.
It is notable that this legend seems to have been originated by the Greeks, not the Romans. The Greeks were interested in Aeneas, not Rome, but the Romans happily adopted this hellenocentric legend as part of their native tradition.
Hellanicus and Damastes are the earliest literary proofs that we have, but many scholars believe that the legend was firmly established in central Italy a century earlier. The Aeneas legend was popular among the Etruscans, and one theory is that this is how the Romans came to learn of it. Lavinium, to the south of Rome, also claimed a Trojan origin. They continued the cult of Aeneas even into Roman times.
The Romans continued to develop this tradition and at times it came in useful, like when the Sicilian town of Segesta allied with the Romans during the war against Carthage because they both claimed Trojan descent.
It could also cause problems, such as when Pyrrhus of Epirus claimed descent from Achilles and claimed the attack on Rome was a new Trojan War in 280 BC. It is possible that this war really helped to solidify the idea among Romans that they were descended from Aeneas.
As Rome became more powerful and politically active with the Greek world, the idea that they were Trojans became even more firmly established, both at home in Rome and in the wider Mediterranean area. Virgil was just the culmination of this process, and it is interesting that he used the legend for political-nationalistic reasons just as the earlier Romans did.
Main source: T.J. Cornell, The Beginnings of Rome (1995)
Edit: "founded by Virgil" to "founded by Aeneas"
To add to the beautiful answer by u/BaffledPlato, I think it would also be fair to add that Virgil came as part of a long line of poetic tradition that based itself on a flourishing cultural understanding within the psyche of the Roman people. In other words, Virgil probably based the Aeneid and all the events therein on already established stories, myths, literature and oral accounts of the past of the Roman people. Another earlier poet in the literary tradition, Ennius, states:
[...] he had three hearts, because he knew how to speak in Greek and Oscan and Latin.” (Ennius transmitted by Aulus Gellius, Attic Nights 17.17.1)
I think you can use this as evidence that while the Romans definitely had Aeneus kick-starting the whole Roman race malarkey, there was also an awareness that the Roman race was a bit of a conglomerate of peoples and languages. Add into the mix this nugget from Virgil:
Here kings of Hector’s race will reign now for three hundred years complete, until a royal priestess, Ilia, heavy with child, shall bear Mars twins. Then Romulus will further the race, proud in his nurse the she-wolf’s tawny pelt, and found the walls of Mars, and call the people Romans, from his own name. I’ve fixed no limits or duration to their possessions: I’ve given them empire without end. Why, harsh Juno who now torments land, and sea and sky with fear, will respond to better judgement, and favour the Romans, masters of the world, and people of the toga, with me. So it is decreed. A time will come, as the years glide by, when the Trojan house of Assaracus will force Phthia into slavery, and be lords of beaten Argos. From this glorious source a Trojan Caesar will be born, who will bound the empire with Ocean, his fame with the stars, Augustus, a Julius, his name descended from the great Iulus. -BkI:257-296 Jupiter’s Prophecy, The Aeneid
From this, we know that technically the Romans weren't the Romans until after Romulus. But Augustus was deliberately claiming decadency from Iulus which gives him a linage back to Venus. Which Julius Caesar (and the Julii in general) had been claiming for a while as evidenced by this coin depicting Venus
With the clear intent of being reappointed dictator for the second time, Caesar advertised his divine descent by placing the wreathed head of Venus Genetrix in profile on the obverse of this silver denarius (minted in Africa 47/46 BCE); the reverse contains the image of Aeneas carrying Anchises and holding the Palladium (Berlin, Pergamon Museum). (see more coins here)
What I'm trying to say is that Virgil's epic while probably part of the Augustan scheme of legitimacy is only a part of the Roman understanding of their own origins and cultural/linguistic background. Virgil, although a genius and rightly deserving of his place in history and literature, probably still wasn't capable of convincing the whole of the Roman 'race' of an origin that wasn't already understood and perpetuated within their own mythology and closeness with Greek culture.
EDIT: wording in the first paragraph. Attic Nights attribution to Aulus Gellius and Ennius made clearer.