Behavioral decision theory argues that humans can adjust their third-party responses (e.g., punishment and compensation) to injustice by integrating unfair experiences. Typically, the mood plays an important role in such a decision-making process. However, the underlying neurocognitive bases remain largely unclear. We first employ a modified third-party justice game in which an allocator split an amount of money between oneself and a receiver. The participants can reapportion the money as observers by choosing from the following three costly options: compensate the receiver, accept the current allocation, or punish the allocator. Then, a second-party pseudo interaction is conducted where participants receive more (i.e., advantageous unfair experience) or less (i.e., disadvantageous unfair experience) than others. Finally, participants perform the third-party justice game again after unfair experiences. Here, we use functional near-infrared spectroscopy (fNIRS) to measure participants' brain activities during third-party responses to injustice. We find participants compensate more to the receiver after advantageous unfair experience, which involved enhanced positive emotion, weakened sense of unfairness, and is linked with increased activity in the right dorsolateral prefrontal cortex (rDLPFC). In contrast, participants punish more on the allocator after disadvantageous unfair experience, which might primarily stem from their negative emotional responses, strong sense of unfairness, and is associated with significantly decreased activity in the rDLPFC. Our results suggest that third-party compensation and punishment involved differential psychological and neural bases. Our findings highlight the crucial roles of second-party unfair experiences and the corresponding mood responses in third-party responses to unfairness, and unravel the intermediate neural architecture.