The integration of renewable rnergy sources (RESs) into the power grid involves operational challenges due to the inherent RES energy-production variability. Imbalances between actual power generation and scheduled production can lead to grid instability and revenue loss for RES operators and aggregators. To address this risk, in this paper, we introduce a mutually beneficial bilateral trading scheme between a RES and a DR aggregator to internally offset real-time energy imbalances before resorting to the flexibility market. We consider that the DR aggregator manages the energy demand of users, characterized by uncertainty in their participation in DR events and thus the actual provision of flexibility, subject to their offered monetary incentives. Given that the RES aggregator faces penalties according to dual pricing for positive or negative imbalances, we develop an optimization framework to achieve the required flexibility while addressing the trade-off between maximizing the profit of the RES and DR aggregators and appropriately incentivizing the users. By using appropriate parameterization of the solution, the achievable revenue for the imbalance offsetting can be shared between the RES and the DR aggregators while keeping users satisfied. Our analysis highlights the interdependencies of the demand–production energy imbalance on user characteristics and the RES and DR aggregator profits. Based on our results, we show that a win–win outcome (for the RES and DR aggregators and the users) is possible for a wide range of cases, and we provide guidelines so that such bilateral agreements between RES and DR aggregators could emerge in practical settings.