SOFIA VERGARA‘s boyfriend nearly lost his life in a terrifying car crash — but his bone-shattering brush with death saved their romance… and their wedding plans.

When the “Modern Family” star got word that trust-fund heir Nick Loeb was critically injured after his car careened off a cliff, “she dropped everything and rushed to his side,” a family friend told The ENQUIRER.

“Sofia went to pieces. She sobbed with fear and prayed. She was terrified she’d lose him.”

As The ENQUIRER recently reported, the 38-year-old beauty had pulled the plug on her marriage and baby plans with Nick because of his jealousy over her skyrocketing career.

But then on Aug. 23 came the frightening news that Nick, 35, had wrecked and was rushed to a Los Angeles-area intensive care unit with a broken leg and pelvis and a deep gash across his chest.

Divulged the friend: “Now Sofia is telling friends that the wedding is back on and will happen as soon as Nick recovers."

The normally-private Sofia even tweeted a pic of Nick in his hospital bed on Wednesday while professing her love for him.

Pick up the new issue of The ENQUIRER to read the full story!