In 508bc Lars Porsena besieged Rome in an attempt to bring Tarquinius Superbus back on his throne. After his failure with the troops from Tarquinii, Tarquinius went to Porsena, king of Clusium (mod. Chiusi) In the hope the king Lars Porsena would help him.
And indeed Porsena would send ambassadors to Rome to demand that Tarquinius would be admitted to Rome or at least his properties would be returned. As expected to Romans refused and Porsena declared war. He advanced with his army to Rome. He took the hill Janiculus on the west side of the Tiber, where the Romans had a permanent , possibly reinforced guard.
Now he advanced to Rome. According to Livius(2.10) a small group of Romans (possibly the guard of the Janiculus) stormed back to the city. Dionysius(5.23) and Plutarchus(LoP 16) mean that the consuls came out of the city with their armies and a battle took place. To me this is not very likely: Even if the Roman army had been assembled it would have taken them at least 20 minutes to cross the bridge and Porsena was storming to the city. Even if they got out in time to take their battle line and fought, then when they had lost and would try to cross the bridge again in panic(!) this would have taken them more than an hour, time enough for a slaughter.
In both situations Cocles would have blocked the enemy. First with two comrades and in the end on his own. Until the bridge had been destroyed by the Romans. But probably he was commanding a relatively small group. If he were on his own he simply would have been pushed aside by the Etruscan phalanx. When the bridge had been destroyed he jumped into the river with all his arms and swam back to Rome. This seems unlikely, but is not entirely impossible. Presuming he was not wearing chain mail, but a breastplate and a shield mainly made of wood even very possible. Even modern soldiers learn how to swim with their arms and how to keep their fire-arm dry. ut according to Polybius(6.35) the man drowned. Roman virtue at it's best. Plutarchus(5.23) even points out that Horatius was a descendant of Marcus Horatius
Gaius Mucius proposed to the senate to sneak out of the city and go to Porsena's camp in order to kill the him. And so he did, but once there he mistook another man for the king and slew him instead of the king. After this he somehow convinced Porsena to make peace with Rome.
Porsena indeed made peace with the Romans without restoring Tarquinius' power. As usual in the ancient times hostages were exchanged. Among them a group of young women. Cloelia and some other women escaped back to Rome, but the noble Romans sent them back to Porsenna.