I was a surface sailor in the USN. I saw collisions, fires, electrical shocks, people falling overboard. Being at sea is dangerous. For some of the reasons why this could happen, read this blog from a former destroyer captain: How Could This Happen? The Fitzgerald, the U.S. Navy, and Collisions at Sea
Basically, it's dark, sometimes your radar is turned off for tactical reasons, sometimes it's less effective due to weather, sometimes you are in heavy shipping lanes with dozens of tracks (other ships, boats, rowboats) going at once. If a ship suddenly changes course, you sometimes need a few minutes to determine that, by watch standers or radar. If you are both going 15 Knots, it doesn't take long to hit.
Imagine an empty shopping mall parking lot, at night, with no lights on. You turn 15 or 20 cars loose, to drive wherever they want to go by any route....not using the lanes between the parking spots. You tell them to "watch out for others", and then you let the navigation continue all night long..... That's being at sea.
Yes, ships have a collision alarm that can be sounded. Sometimes in the heat of maneuvering people forget to hit it.