Forests play an enormous role throughout the invented history of Tolkien's Middle-earth and are inevitably an important episode on the heroic quests of his characters. The forest device is used as a mysterious transition from one part of the story to another.
In The Hobbit, The Lord of the Rings, and associated writings, the expansive forest of Greenwood the Great was called Mirkwood. In this instance, the name is supposedly a translation of an unknown Westron name. Around the year 1050 of the Third Age, 'the shadow of Dol Guldur' fell upon it, and men began to call it Taur-nu-Fuin and Taur-e-Ndaedelos (Sindarin: forest of great fear). The shadow was the power of Sauron who, under a concealed identity, established himself at the hill-fortress of Dol Guldur on Amon Lanc. The presence of Sauron's minions drove the Elves (now led by Thranduil, son of Oropher) further northward, so that by the end of the Third Age they were a diminished and wary people who had entrenched themselves beyond the Mountains of Mirkwood (Emyn Fuin, formerly the Emyn Duir or "Dark Mountains"). The Old Forest Road or Old Dwarf Road crossed the forest east to west, but due to its relative proximity to Dol Guldur, the road was mostly unusable. The Elves made a path farther to the north, which ended somewhere in the marshes south of the Long Lake of Esgaroth.
In The Hobbit, Bilbo Baggins, along with Thorin Oakenshield and his band of Dwarves — minus the Wizard, Gandalf — ventured into Mirkwood during their quest to regain Erebor from the Dragon Smaug. During their passage through Mirkwood, the party encountered and was captured by many Giant Spiders, descended from Shelob. Shortly after the dwarves' escape they were taken prisoner by the Elves and brought before Thranduil, who imprisoned the dwarves. While unclear, it was shortly after or possibly even during these events, that the White Council flushed Sauron out of Dol Guldur, and as he fled to Mordor his influence in Mirkwood diminished for a while.
Years later, Gollum, after his release from Mordor, was captured by Aragorn and brought as a prisoner to Thranduil's realm. Out of pity, they allowed the creature some freedom to roam the forest (under close guard). Gollum escaped custody during an Orc raid, and fled south to Moria in search of the One Ring.
After Sauron's destruction at the conclusion of the Third Age, Mirkwood was cleansed by Galadriel and became known as Eryn Lasgalen, Sindarin for the Wood of Greenleaves.