Biogen Inc. agreed to pay $22 million to resolve U.S. allegations that the company illegally used two charities that help cover Medicare patients’ out-of-pocket drug costs as a means to pay them kickbacks to use the Cambridge, Mass-based drugmaker’s multiple sclerosis medicines.

Advanced Care Scripts Inc. will pay $3.5 million to resolve allegations that the Florida-based specialty pharmacy served as a conduit for a Teva Pharmaceutical Industries Ltd. subsidiary to pay kickbacks to Medicare patients, the U.S. Justice Department said.