Which of the pilots flies when it gets dangerous?
In the end it's all up to the Captain.  If the FO is PF, which with most airlines alternates with each leg of a block, and something exciting happens, the capt may let the FO continue flying if the capt feels the FO has things under control.  Or the capt may say "I have control" and take over.  Depends.  

The Pilot In Command is pilot in command.  He/she commands, but with modern CRM rules, there is expected to be some mutual consultation and decision making, so the command authority has to take all that into account.

AF447 was an unusual situation where the capt didn't realize early enough what a clusterfark the two FOs sitting in the front seats had gotten themselves into, who were both mentally overloaded into a tunnel vision state, and especially the right seater, who appeared to lack basic fully internalized flying skills, sitting in panic mode with the stick full aft for almost the entire ride down.