This story has something of a complicated history to it. In 1986, NBC started airing a TV sitcom starring Valerie Harper as a mother of three boys and wife of an airline pilot, entitled Valerie. Its 13-episode trial season was a success, and it was renewed for another season which was equally successful. A third season had been greenlit and was just starting production before Harper was involved in a salary dispute, resulting in her getting fired from the show. As a result, her character was killed off in a car accident, Sandy Duncan was brought in as the boys' aunt, and the show was renamed Valerie's Family.
Several episodes of season 3 deal with the Hogans overcoming Valerie's death. The third episode, entitled "Burned Out" and aired during Fire Prevention Week on October 5, 1987, is one such episode. In the episode, as the boys and their father are helping Sandy move in, they come across a poorly-structured lamp in their attic. As they walk away from it, the lamp sparks and catches fire. The fire contains itself well enough that the Hogans don't even notice anything wrong until they're getting ready for bed. As fate would have it, the fire eventually engulfs the house and leaves the Hogans to stay with their next-door neighbors, the Pooles, while their house is being repaired.
This is where McDonald's comes in. The restaurant helped finance the set damage for the scene involving the Hogans exploring their charred house. In exchange for this, they sponsored that episode and aired commercials promoting fire safety during it. While "Burned Out" is in regular circulation, the commercials that aired during this episode don't seem to be - they're not even on YouTube.
(Oh, and for an extra bit of irony, the actor who played Mr. Poole in this episode, Willard Scott, is known for originating the Ronald McDonald character.)