Variable renewable energy producers and electricity retailers encounter several uncertainties in their decision-making problems, such as intermittency of renewable energy sources, variability of consumption, and market price volatility. To cope with these uncertainties, this paper presents a new contract-based trading mechanism of power flexibility (FlexCon) between two parties, a variable renewable energy producer and an electricity retailer. The proposed mechanism is managed by a new entity, named FlexCon operator, to oversee the energy and financial trades through the contract and coordinate the transactions with the system operator. Through the FlexCon, the parties are able to exchange their energy imbalances as a source of power flexibility to alleviate the negative impacts of uncertainties in their decision-making problems. To this end, two two-stage stochastic linear problems are introduced from each party’s point of view. In the first stage, the variable renewable energy producer and the electricity retailer submit their bids to sell and purchase in the day-ahead market, respectively. Following the day-ahead market clearing, closer to the delivery time, the parties submit their decisions on the contract to the introduced FlexCon operator. The operator allocates possible power flexibility transactions based on the surpluses or shortages of the parties. Assuming that the imbalances are not completely resolved with the FlexCon, the remaining deviations are settled in the balancing market. The parties’ decisions related to the balancing market and the FlexCon are modeled in the second stage of the stochastic problem. The uncertainties associated with prices, renewable generation, electricity consumption, and the maximum exchangeable power flexibility through the FlexCon are considered via scenarios. Meanwhile, the profit risk is considered by the Conditional Value at Risk measure. The numerical results show that FlexCon effectively diminishes the impacts of uncertainties on the parties’ profit.