Thinking about the TNG episode "Disaster", Lt. Munroe was killed during the impact. The episode plays out with Deanna taking command, but what would have happened if the only remaining crew on the bridge were non-commissioned officers? For instance, if O'Brien and other chiefs were the only survivors of the bridge? Is there a canon reference for chain of command in such a situation?
In the episode DS9: Valiant, we encounter a ship that was on a training cruise. The senior staff all died and the remaining officer gave command to the highest ranked cadet.
WATTERS: (tolerant) "Sir" is correct, ensign. I was given a battlefield commission and command of this vessel by the late Captain Ramirez. Using that authority, I've also commissioned and promoted other members of Red Squad as needed.
Note that in this instance, instead of doing what's appropriate (e.g. navigating the ship to the nearest real officer to allow them to take over) Watters has been playing at being captain because he doesn't want to stop.
As to what would happen if this was a normal crew, the NCO with the highest rank would almost certainly have taken charge. Everyone on the ship that isn't a civilian holds a rank.
In the event that a senior officer is missing, everyone defers to the next most senior all the way down to Crewman 3rd class, which is basically the guy who makes sure the vending machines don't run out of fun-size Munchie Bars.