Exercise can act in synergy with caloric restriction to maintain/increase lean body mass while losing fat mass. The goal should be fat loss rather than weight loss (which includes loss of muscle mass).

In short, it seems like we do not have as much control as we like to think we have. Most people who go on a diet, regain lost weight within a couple of years. Yet, there are many things we can do to improve our body composition.

Biological control of appetite: A daunting complexity - MacLean - 2017 - Obesity - Wiley Online Library: “It is this individual variability in the predisposition for obesity and in the biological response to weight loss that makes the biological component of appetite regulation so complicated. When this individual biological variability is placed in the context of the diverse environmental and behavioral pressures that also influence food eating behaviors, it is easy to appreciate the daunting complexities that arise with the self-regulation of appetite.”

Biology's response to dieting: the impetus for weight regain: “The preponderance of evidence would suggest that the biological response to weight loss involves comprehensive, persistent, and redundant adaptations in energy homeostasis (...) To be successful in the long term, our strategies for preventing weight regain may need to be just as comprehensive, persistent, and redundant, as the biological adaptations they are attempting to counter.”

Energy balance and obesity: what are the main drivers? - PubMed - NCBI: “Energy intake that exceeds energy expenditure is the main driver of weight gain. The quality of the diet may exert its effect on energy balance through complex hormonal and neurological pathways that influence satiety and possibly through other mechanisms. The food environment, marketing of unhealthy foods and urbanization, and reduction in sedentary behaviors and physical activity play important roles.”

Calories do count: "In any given subject, the rate of weight loss was essentially constant throughout the entire study. It is therefore obvious that the significant factor responsible for weight loss is reduction of calories, irrespective of the composition of the diet."

The dynamics of human body weight change: "An imbalance between energy intake and energy expenditure will lead to a change in body weight (mass) and body composition (fat and lean masses). (...) Here, we show that a mathematical model of the macronutrient flux balances can capture the long-term dynamics of human weight change"

Predicting metabolic adaptation, body weight change, and energy intake in humans: "Complex interactions between carbohydrate, fat, and protein metabolism underlie the body's remarkable ability to adapt to a variety of diets. But any imbalances between the intake and utilization rates of these macronutrients will result in changes in body weight and composition. Here, I present the first computational model that simulates how diet perturbations result in adaptations of fuel selection and energy expenditure that predict body weight and composition changes in both obese and nonobese men and women. (...) The validated model was used to estimate free-living energy intake during a long-term weight loss intervention, a variable that has never previously been measured accurately."

The Hormonal Control of Food Intake: “The genetic evidence for a critical role of leptin and its downstream anorexigenic pathways in the control of food intake is extremely strong and highly suggestive of a system with little redundancy.”

Adenovirus 36 and Obesity: An Overview: “Evidence emerging over the last 20 years supports the hypothesis that viral infections may be associated with obesity in animals and humans. The most widely studied infectious agent possibly linked to obesity is adenovirus 36 (Adv36). Adv36 causes obesity in animals. In humans, Adv36 associates with obesity both in adults and children ”