"Wizards of Waverly Place" star David Henrie used some legal magic to dodge jail time in his airport gun case -- and by magic we mean ... he took a plea deal.
The actor pled no contest Wednesday to possessing a weapon at the airport ... according to the court clerk. We're told Henrie was sentenced to 2 years probation and 20 days of community labor, but he won't spend any time behind bars.
David also has to take a gun safety course and drop some cash for fines and fees.
We broke the story ... Henrie was originally charged with 3 crimes after being busted at LAX with a loaded gun in September. As part of the deal, he got 2 charges dropped -- carrying a loaded firearm and carrying a concealed firearm.
He was facing up to a year in jail ... so he should be extra thankful on Thursday.