Living organisms are often exposed to extreme dehydration, which is detrimental to the structure and function of the cell membrane. The lipid membrane undergoes fluid-to-gel phase transition due to dehydration and thus loses fluidity and functionality. To protect the fluid phase of the bilayer these organisms adopt several strategies. Enhanced production of small polar organic solutes (also called osmolytes) is one such strategy. Urea and trimethylamine N-oxide (TMAO) are two osmolytes found in different organisms combating osmotic stress. Previous experiments have found that both these osmolytes have strong effects on lipid membrane under different hydration conditions. Urea prevents the dehydration-induced phase transition of the lipid membrane by directly interacting with the lipids, while TMAO does not inhibit the phase transition. To provide atomistic insights, we have carried out all-atom molecular dynamics (MD) simulation of a lipid membrane under varying hydration levels and studied the effect of these osmolytes on different structural and dynamic properties of the membrane. This study suggests that urea significantly inhibits the dehydration-induced fluid-to-gel phase transition by strongly interacting with the lipid membrane via hydrogen bonds, which balances the reduced lipid hydration due to the decreasing water content. In contrast, TMAO is excluded from the membrane surface due to unfavorable interaction with the lipids. This induces further dehydration of the lipids which reinforces the fluid-to-gel phase transition. We have also studied the counteractive role of TMAO on the effect of urea on lipid membrane when both the osmolytes are present. TMAO draws some urea molecules out of the membrane and thereby reduces the effect of urea on the lipid membrane at lower hydration levels. This is similar to the counteraction of urea's deleterious effects on protein by TMAO. All these observations are consistent with the experimental results and thus provide deep molecular insights into the role of these osmolytes in protecting the fluid phase of the membrane, the key survival strategy against osmotic-stress-induced dehydration.