DeeV's answer should be the accepted (/EDIT: done by OP since then) and the most upvoted one. My answer here is only necessary to debunk the currently top voted answer, which unfortunately propagates a common misconception about diets, so please see it as a complement (with a few practical tips for OP near the end).
There is a common claim that most dieters will regain their weight or even more. This is blatantly false and comes from an old bogus study. Since then, it was shown by several systematic reviews and meta-analyses that long-term (2-5 years post diet), the weight loss persists, although with a rebound yes compared to the lowest, but the total weight remains lower than pre-diet, with estimates being an average of >3kg of weight loss and >3% of total weight loss 5 years post-diet (ref 1, ref 2).
Figure excerpt from this meta-analysis. Data from the Look AHEAD multicentric trials on diabetes and obesity management. The strict very low calories diet was enforced during the first 6 months, with gradual tapering off to higher calories the remaining of the 1st year, then off-site prescriptions of replacement meals and lifestyle changes such as physical exercise but little to no monitoring beyond the first year.
Extended figure from the same data excerpt from here that goes up to 8 years after the start of the study (7 years post diet). Patients groups are segmented into 3 subfigures depending on their initial weight loss during the 1st year, and then into 4 line charts depending on their weight variation. Sadly, still no variability intervals, but the segmentation provides insights into the variability. We can still see that most dieters still kept some weight loss 7 years post diet.
From this figure, you will notice a few interesting facts: 1) all diets (that restrict calories intake) are correlated with long-term weight loss years post-diet, 2) exercise alone is ineffective for weight loss. These results are reproduced in loads of systematic reviews and meta-analyses on diets (I only picked here a few for conciseness, you can lookup on pubmed for more).
The latter may seem surprising, but it is in fact well known among obesity researchers, that dieting with calories restriction is much more effective and the primary treatment to reduce weight, and physical exercise only comes second to improve cardiometabolic function but not reduce weight (and weight reduction is the best predictor of long term improvement in metabolic disorders, including obesity but also diabetes and MASLD/NAFLD).
Very-low-energy-diets cause an impressive but temporary trough that does not last likely due to glycogen stores loss, which store water, so this trough is basically just water loss, not fat loss.
The best predictor for long term weight loss hence appears to be in several large studies such as the Look AHEAD trials not the diet itself, but rather adherence (ref 1, ref 2, ref 3). Recent evidence even suggest that it's not even adherence to the diet, but adherence to monitor and control one's own weight regularly that is the key to weight loss. Indeed, in a recent study, the researchers found that post-diet individuals who used a weight scale regularly to monitor their weight kept on average more weight off over the long term (ref1, ref2).
That said, depending on the type of diet you are doing, and the composition of macronutrients, this will have different effects on what you lose: if there is no protein in your diet, of course you will lose not just fat but also certainly some lean mass/muscles. On the other hand if there is enough proteins in your diet (not too much to avoid liver issues due to proteins poisoning), then you may be able to keep your lean mass, but without carbohydrates it will be near impossible to gain any new lean mass.
One last interesting note I remember is that even if you use a diet that is rich in proteins (but low calories or lacking carbohydrates, eg, ketogenic diet), studies found that physical exercise improves the chances of keeping lean mass. So if your goal is to keep your lean mass while losing weight, you definitely should consider physical exercise on top of dieting.
Another recent finding is that sleep appears to affect weight gain, with shorter sleep associated with weight regains at 1 year post diet (ref). It's also worth noting that the insulin and melatonin (sleep hormone) are tightly coupled since there are antagonistic receptors on the pancreas.
Finally, after you reached your weight goals, transitioning to a more balanced and sustainable healthy diet such as DASH or the mediterranean diet or vegetarian diet is highly recommended, as there are plenty of evidence that these 3 diets have cardiometabolic protection benefits, as the Dietary Guidelines for Americans 2020-2025 states (ref 1, ref 2). It is also important to know how to recognize and avoid dangerous fad diets, not all of them are dangerous, but the ones recommending to eat inedible items or to restrict whole types of nutrients are usually dangerous (only exception for the latter are allergies out of the top of my head).
Disclaimer: I significantly contributed to Wikipedia (in English) articles on metabolic disorders and diets using evidence-based medicine sources and I was attributed awards for my work on several of these articles (so I highly recommend you read those too of course! And the WHO materials too).
(PS: if link for this ref dies, use this doi instead).