Deducing that Howl is trying to protect the castle and everyone inside it, Sophie moves everyone out and removes Calcifer from the fireplace, and destroys the castle. She offers Calcifer her braid, allowing him to power a portion of the remaining castle. They head toward Howl, in order to let him know that they are not attached to the castle anymore when the former Witch of the Waste realizes that Howl has given his heart to Calcifer, just like Sophie did with her hair. The Witch takes Calcifer and refuses to let go of him although it is burning her. A panicked Sophie pours water onto the Witch of the Waste, which douses Calcifer, making him lose his magical strength and power. The castle is split in two; Sophie and Heen fall down a chasm, while Markl, the Witch of the Waste and Calcifer continue traveling on the disintegrating castle.
Making her way toward Howl's heart with the ring that Howl gave her as a protective charm, Sophie enters through the broken door of the castle into the black region and discovers a recollection of how Howl and Calcifer met: as a boy, Howl took pity on a falling (dying) star—Calcifer—and gave it his heart. The act bound Calcifer to Howl indefinitely; however, by losing his heart, Howl was emotionally trapped in adolescence.
Sophie finds Howl, having now lost his human consciousness in bird form. They head back to Calcifer, accompanied by the Witch of the Waste and Markl who are on a plain wooden platform, the only remaining part of the former castle, moving on the edge of a cliff. Sophie asks the Witch for Howl's heart. She gives it to her and Sophie places the heart back inside Howl, returning him to life, and freeing Calcifer. With Calcifer gone, the remaining platform collapses and starts falling down the mountain. Turnip-head saves the plaftorm by putting his pole against the falling platform. Sophie warmly kisses Turnip-head on the cheek as thanks, which breaks his curse revealing that he is actually the missing prince from the neighboring country and was trapped in the form of a scarecrow until he received a true love's kiss. Although Calcifer is now free, he returns to his former company. Heen shows the scene of the happy end and the discovery of the missing prince to Suliman, and Suliman decides to put an end to the war. Howl, Sophie, and the others are seen high above the bomber planes upon a new flying castle, while the bombers return from the war.
Source: http://en.wikipedia.org/wiki/Howl's_Moving_Castle_(film)