Recommending safe and effective medication (drug) combinations is a key application of artificial intelligence in healthcare. Current methods often focus solely on recommendation accuracy while neglecting drug–drug interactions (DDIs), or overly prioritize reducing DDIs at the cost of model performance. Therefore, we propose the Attention-guided Multi-Graph collaborative decision Network (AMGNet) for safe medication recommendation, which strikes a balance between improving recommendation accuracy and minimizing DDIs. Specifically, AMGNet designs a patient feature encoder that utilizes a transformer encoder–decoder architecture to learn the temporal dependencies of longitudinal medical features from patient visits, effectively capturing the patient’s medication history and health status to enhance recommendation accuracy. AMGNet is also equipped with a medication feature encoder that integrates diverse knowledge graphs of drug molecular structure, electronic health records(EHRs), and drug–drug interactions(DDIs) through multi-graph representation learning and contrastive learning methods, further reducing the DDI rate of the recommended medication combinations and mitigating the risks associated with drug co-administration. We conducted extensive experiments on the widely used MIMIC-III and MIMIC-IV clinical medical datasets. The results demonstrate that AMGNet achieves competitive performance. Additionally, ablation studies and detailed case analyses further confirm that AMGNet offers high precision and safety in medication recommendation.