Answer: As for your prayer in the situation you described—when you found the mosque full, could not find room inside, and therefore prayed outside on the pavement next to the mosque while hearing the imam—the prayer is valid in this circumstance out of necessity, provided you did not stand ahead of the imam.
However, if there is a roadway between the worshipper and the mosque, as you mentioned at the end of your question, then following the imam is not valid in that case. If people and cars are using the road during the prayer, the prayer is invalid. But if the rows extend across the road all the way to where you are standing so that the entire area has effectively become a prayer space, then the prayer is valid in that case.
If, on the other hand, the road remains in use and the rows are not continuous, the prayer under such circumstances is invalid, because you are disconnected from the imam and separated from him by passers-by. Allah knows best. The jurists give a similar ruling when there is a river—or a canal in which boats travel—between the worshipper and the mosque.
Question: You have said that if the rows reach across the road the prayer is valid. How do we reconcile this with the prohibition against praying in the middle of a roadway?
Answer: This is allowed out of necessity. When the mosque is full, people pray outside, and the rows are connected, the prayer is valid even if they are standing in what is originally a street or a marketplace where people normally walk. Because of the need and necessity in such situations—especially on Fridays and on days when crowds are large—there is no harm in doing so, Allah willing, due to the need.