This study aims to generate high-quality synthetic Computed Tomography (sCT) from Magnetic Resonance Imaging (MRI) in order to facilitate MRI-based radiation therapy treatment planning. An MRI-to-CT Transformer-based Denoising Diffusion Probabilistic Model (CT-DDPM) is proposed to utilize a diffusion process with a V-shaped Shifted-window Transformer network (Swin-Vnet) to transform MRI into sCT. The model comprises two processes: a forward process of adding Gaussian noise to ground truth CTs to create noisy volumes, and a reverse process of denoising the noisy CT scans using the Swin-Vnet conditioned on the corresponding MRI. With an optimally trained Swin-Vnet, the reverse process generates sCTs from MRI. The method is evaluated using Mean Absolute Error (MAE) of Hounsfield unit (HU), Peak Signal-to-noise Ratio (PSNR), Multi-scale Structural Similarity Index (SSIM) and Normalized Cross-Correlation (NCC) between ground truth CTs and sCTs. Evaluated on a brain dataset, CT-DDPM demonstrated state-of-the-art quantitative results, exhibiting an MAE of 45.210±3.807 HU, a PSNR of 26.753±0.861 dB, an SSIM of 0.964±0.005, and an NCC of 0.981±0.004. Evaluated on a prostate dataset, the model also showed impressive performance with an MAE of 55.492±8.281 HU, a PSNR of 28.912±2.591 dB, an SSIM of 0.894±0.092, and an NCC of 0.945±0.054. Across both datasets, CT-DDPM significantly outperformed competing networks in most metrics, as shown in paired t-test. The source code is available at: https://github.com/shaoyanpan/Synthetic-CT-generation-from-MRI-using-3D-transformer-baseddenoising-diffusion-model