Warning: Wikipedia contains spoilers.
Dorothy Gale, with a kitten named Eureka, is sent by her Uncle Henry and Aunt Em to visit her uncle in California who operates Hugson's Ranch. She strikes up an acquaintance with Hugson's son—and her cousin—Zeb. Dorothy, Eureka, and Zeb are riding a buggy being pulled by a cab-horse named Jim when an earthquake starts and opens a crevice beneath them that sends them hurtling into the bowels of the earth.
Dorothy, Eureka, Jim, Zeb, and the buggy alight in the land of the Mangaboos, a vegetable people who accuse them of causing the Rain of Stones (what the Mangaboos call the earthquake because they're beneath the surface of the earth, and earth instead falls on them). Zeb is surprised by this strange new land, but Dorothy surmises that they're in a fairy country because they're meeting vegetable people and the animals—Jim and Eureka—are now speaking. Just as they're about to be sentenced to death by the Mangaboos, a hot air balloon falls out of the sky, and in the basket is the Wizard of Oz, whom Dorothy last met as he floated away from the Emerald City.
The Wizard brags about his showmanship and with the others' aid attempts to awe the Mangaboos into sparing their lives. After defeating their wizard Gwig by slicing him in half—and showing him, as a vegetable, completely hollow inside—he's appointed by the Mangaboo prince as their temporary wizard. The Wizard, Dorothy, and Zeb escape the fate of all intruders—to be cut up and planted—for a while when they release a Princess from the garden who assumes authority. The Prince will now lose his authority and be planted himself. But the cold Princess vows to have Jim and Eureka killed nonetheless, so they all plan to escape higher into the earth where the Mangaboos cannot follow them due to the stronger pull of gravity the further they rise.
Dorothy, Eureka, Zeb, Jim, and the Wizard enter a beautiful green valley and the Wizard's nine tiny piglets devour an enticing fruit which they find makes them invisible. They enter a seemingly empty castle and are welcomes by invisible people, for they have entered the Valley of Voe, whose inhabitants hide from marauding bears by being invisible to them. The inhabitants of Voe help them escape the bears and explain what lies ahead, particularly the terrible Gargoyles. (A story the Voe people tell seems to indicate that by now Baum had decided that people in a fairy land don't die; even cut into pieces, an individual is still active and aware. See The Tin Woodman of Oz for another example of this.)
The companions reach the base of Pyramid Mountain and meet the Braided Man halfway up. He was once a posthole digger who one day fell into a hole he'd dug and since then kept shop here, making hair braids. His facial hair has gotten so long, however, that he's had to braid it to keep from tripping. They head into the land of the Gargoyles and at first repel them successfully because the winged wooden creatures are startled by loud noises. However, they do not tire and soon imprison Dorothy and her friends. They manage to escape the Gargoyles' grasp, however, using their detached wings and Jim's guidance.
After a close encounter with the Dragonettes, baby dragons whose mother has tied their tails to a post until she returns from hunting, Dorothy suggests that she signal Ozma to bring them to Oz by using the Magic Belt which she'd captured from the Nome King in Ozma of Oz. She does so at a prearranged time of day, and Dorothy, the Wizard, Jeb, Eureka, and Jim arrive within the Emerald City.
Soon after renewing his acquaintance with the Emerald City staff and making the acquaintance of Ozma, the Wizard elects to remain in Oz permanently. The others' visit is highlighted by the wooden Saw-Horse beating Jim in a race and the trial of Eureka for eating Ozma's pet piglet gifted to her by the Wizard. Ozma then uses the Magic Belt to send Dorothy, Eureka, Jim, and Zeb back to California.