Involuntary organ movement causes degradation in myocardial perfusion (MP) positron emission tomography (PET) imaging. Respiratory and/or cardiac gating reduces motion while lowering statistics in the reconstructed image frames. The advent of integrated PET/magnetic resonance imaging (MRI) provides opportunities for motion-compensated PET imaging using MRI measured motion. The purpose of this study is to correct respiratory and cardiac motion in dual-gated MP PET imaging, with non-rigid cardiac motion estimated from corresponding cardiac-gated MR images. Using the XCAT phantom, we simulated five-dimensional (5D) dual-gated PET data with and without MP defects and the corresponding 4D cardiac-gated MR images. For each cardiac gate, we performed integrated 4D respiratory motion-corrected image reconstruction to the respiratory-gated data, using the end-expiratory frame as the reference. Then we estimated cardiac motion from the gated MR images using an optical-flow determination algorithm. Using the cardiac motion fields, we warped and summed the respiratory motion-corrected cardiac-gated PET images with the end-diastolic frame as the reference. To evaluate the proposed technique, we performed receiver operating characteristic (ROC) analysis for MP defect detection using a channelized Hotelling observer. The ROC analysis resulted in an area under the curve (AUC) value of.96 ±.02 from images obtained using the proposed respiratory and cardiac motion compensation technique and an AUC value of.85 ±.04 from images reconstructed without motion correction. The proposed MRI assisted motion-corrected image reconstruction technique for dual-gated PET imaging is demonstrated to significantly improve the MP defect detection, which is promising for applications especially in emerging integrated PET/MRI.