Anticipation of danger at first elicits panic in animals, but later it helps them to avoid the real threat adaptively. In zebrafish, as fish experience more and more danger, neurons in the ventral habenula (vHb) showed tonic increase in the activity to the presented cue and activated serotonergic neurons in the median raphe (MR). This neuronal activity could represent the expectation of a dangerous outcome and be used for comparison with a real outcome when the fish is learning how to escape from a dangerous to a safer environment. Indeed, inhibiting synaptic transmission from vHb to MR impaired adaptive avoidance learning, while panic behavior induced by classical fear conditioning remained intact. Furthermore, artificially triggering this negative outcome expectation signal by optogenetic stimulation of vHb neurons evoked place avoidance behavior. Thus, vHb-MR circuit is essential for representing the level of expected danger and behavioral programming to adaptively avoid potential hazard.