Saying “good night” in Japanese is uncharacteristically aggressive, as you are literally insisting that someone take a rest. O-yasuminasai (“good night”) is a combination of the regular form of the noun yasumi (“rest”) and the command form of the verb nasaru. Nasaru is an honorific equivalent of the verb suru (“to do”). The prefix o is also honorific, but you will rarely find this greeting without it, even in the most casual situations. One variation, among family and friends, is to shorten the phrase to o-yasumi.
The suffix -nasai is commonly attached to verbs to make a stern, yet polite imperative. Parents, not to mention teachers, can be heard scolding their children and students in public with various combinations of a verb and nasai. This form sounds more respectful than the plain command form of the verbs: Okite becomes okinasai (“Get up!”), suwatte is transformed into suwarinasai (“Sit down!”), and tabete gets refined to tabenasai (“Eat!”).
Here are some comments you may hear from those who are about to retire for the evening:
Sumimasen, kyuu-ni nemuku natte kita.
Excuse me, I suddenly became very sleepy.
Watashi mo nemui desu.
I'm sleepy, too.
I want to sleep.
Kore kara neru tsumori desu.
I intend to go to bed soon.
Notice how the adjective nemui is conjugated by dropping the i and adding a ku before adding the verbal phrase naru kuru. In the third example, the same adjective is conjugated with the suffix -tai as another way to say “I'm sleepy.”