As a pre-cursor to this answer, as pointed out in the comments by @Himarm, Harbour Chains were in fact used as navigational barriers (and are still used to this day), so it's not actually a stretch for the chain to have done what it did.
The chain was humongous, strong and taut. It easily reached all the way across the bay. It was built by ALL of King's Landing's smiths and metalworkers:
... The gaggle of smiths, armorers, and ironmongers that Bronn had collected fell to their knees.
He hoisted himself up into the high seat under the round golden window and bid them rise. “Goodmen, I know you are all busy, so I will be succinct. Pod, if you please.” The boy handed him a canvas sack. Tyrion yanked the drawstring and upended the bag. Its contents spilled onto the rug with a muffled thunk of metal on wool. “I had these made at the castle forge. I want a thousand more just like them.”
One of the smiths knelt to inspect the object: three immense steel links, twisted together. “A mighty chain.”
“Mighty, but short,” the dwarf replied. “Somewhat like me. I fancy one a good deal longer.
...
“I want every forge in King’s Landing turned to making these links and joining them. All other work is to be put aside. I want every man who knows the art of working metal set to this task, be he master, journeyman, or apprentice. When I ride up the Street of Steel, I want to hear hammers ringing, night or day.
-A Song of Ice and Fire: Book Two - A Clash of Kings, Chapter Fifteen (Tyrion III).
It was fastened on both ends to watch towers and raised using a lever and pulley system:
He [Davos] saw no sign of any boom; the mouth of the river was open, as if to swallow them all. Except
...
The squat towers of raw new stone that stood opposite one another at the mouth of the Blackwater might mean nothing to Ser Imry Florent, but to him it was as if two extra fingers had sprouted from his knuckles.
Shading his eyes against the westering sun, he peered at those towers more closely. They were too small to hold much of a garrison. The one on the north bank was built against the bluff with the Red Keep frowning above; its counterpart on the south shore had its footing in the water. They dug a cut through the bank, he knew at once.
...
Something flashed down low where the dark water swirled around the base of the tower. It was sunlight on steel, and it told Davos Seaworth all he needed to know. A chain boom... and yet they have not closed the river against us. Why?
-A Song of Ice and Fire: Book Two - A Clash of Kings, Chapter Fifty-Eight (Davos III).
Further reading: