CHICAGO (AP) _ A pharmacist described as the mastermind of a $20 million Medicaid fraud scheme was sentenced to 12 years in prison and ordered to forfeit $8 million in illicit profit from the scheme.

Morton Goldsmith, 50, of Skokie, was sentenced Tuesday and fined $150,000, according to Assistant U.S. Attorney Daniel Purdom, who said Goldsmith was ordered to forfeit the $8 million in ''ill-gotten gains.''

Twelve other defendants also were sentenced by U.S. District Judge John F. Grady.

Vito Sblendorio, 42, of Holcomb, Wis., was sentenced to 10 years in prison and ordered to forfeit $2.1 million, Purdom said. Sblendorio was a member of the inner circle that ran the scheme, the prosecutor said.

Other sentences ranged from two years in prison to probation.

''We have to send a message to pharmacists and physicians that they cannot unlawfully distribute drugs and expect to escape incarceration,'' Grady said in handing down the sentences.

Prosecutors had described Goldsmith as the mastermind of the scheme, which they said involved 22 clinic-pharmacies selling sedatives and codeine cough syrup to drug addicts in poor Chicago neighborhoods.

Doctors often ordered bogus medical tests to justify the prescriptions and then made claims to Medicaid for reinbursement, prosecutors said.

The defendants were among 36 people who pleaded guilty or were convicted in the fraud, for which 40 people, including 16 physicians, were indicted by a federal grand jury in February 1984.

One of the defendants has died, and three have been judged incompetent to stand trial.

Purdom has said that, in terms of dollars, the Medicaid scheme was the nation's largest.