Elastic properties are important mechanical properties which are dependent on the structure, and the coupling of ferroelasticity with ferroelectricity and ferromagnetism is vital for the development of multiferroic metal–organic frameworks (MOFs). The elastic properties and energy loss related to the disorder–order ferroelectric transition in [NH4][Mg(HCOO)3] and [(CH3)2NH2][Mg(HCOO)3] were investigated using differential scanning calorimetry (DSC) and dynamic mechanical analysis (DMA). The DSC curves of [NH4][Mg(HCOO)3] and [(CH3)2NH2][Mg(HCOO)3] exhibited anomalies near 256 K and 264 K, respectively. The DMA results illustrated the minimum in the storage modulus and normalized storage modulus, and the maximum in the loss modulus, normalized loss modulus and loss factor near the ferroelectric transition temperatures of 256 K and 264 K, respectively. Much narrower peaks of loss modulus, normalized loss modulus and loss factor were observed in [(CH3)2NH2][Mg(HCOO)3] with the peak temperature independent of frequency, and the peak height was smaller at a higher frequency, indicating the features of first-order transition. Elastic anomalies and energy loss in [NH4][Mg(HCOO)3] near 256 K are due to the second-order paraelectric to ferroelectric phase transition triggered by the disorder–order transition of the ammonium cations and their displacement within the framework channels, accompanied by the structural phase transition from the non-polar hexagonal P6322 to polar hexagonal P63. Elastic anomalies and energy loss in [(CH3)2NH2][Mg(HCOO)3] near 264 K are due to the first-order paraelectric to ferroelectric phase transitions triggered by the disorder–order transitions of alkylammonium cations located in the framework cavities, accompanied by the structural phase transition from rhombohedral Rc to monoclinic Cc. The elastic anomalies in [NH4][Mg(HCOO)3] and [(CH3)2NH2][Mg(HCOO)3] showed strong coupling of ferroelasticity with ferroelectricity.