Parenting.com explains that you can nip a tantrum in the bud if you approach it the right way. The particular example the site refers to when it’s time to take away junior from friends and playtime. It needs to be a gentle extraction, and not like tearing off a bandage.
The site suggests you should “embrace long goodbyes,” meaning you condition them to start preparing to leave before it’s time to go. You should give your child some time to “sign off” from what they’re doing, to avoid a loud protest. That could involve having them say goodbye to each friend, or even say farewell to their toys to ease the blow.