Founded by Elendil and his sons at the end of the Second Age, Osgiliath straddled the Great River Anduin at a point approximately half way between the cities of Minas Anor to the west and Minas Ithil to the east. For over a thousand years, Osgiliath was the capital of Gondor, as well as its largest and most important city. The beginning of the city's decline came in the 15th century, when in 1437 it was sacked and burned by the rebel Castamir's forces during the Kin-strife. The Great Plague of 1636 led to further depopulation, and the city began to fall into ruin; the capital was moved to the more secure Minas Anor. Over the next few hundred years, Gondor endured many military defeats east of the Anduin, especially the fall of Minas Ithil in 2002. Osgiliath became vulnerable to attack and was widely believed to be haunted, as its population continued to shrink. Osgiliath was finally abandoned by the remaining civilian population after being captured (temporarily) by Orcs in the 25th century.
Over the centuries leading up to the War of the Ring, the western part of the ruined city was under the control of Gondor, and was at times provided with a military garrison as a means of defending the crossing of the Anduin. The eastern part, with Ithilien, was disputed territory, under Gondor's control for most of the rule of Denethor II, but occupied by Sauron's forces just before the War.
When, during the War, Sauron launched a full-scale invasion of Gondor west of the Anduin, Osgiliath eventually fell to his forces, but was reclaimed by Gondor after Sauron's ultimate defeat a few weeks later.
After the destruction of the One Ring, Osgiliath was rebuilt, but it never became as great as it once was. Minas Tirith remained the capital and King's city.
The name "Osgiliath" is Sindarin for "City of the Host of Stars". The most prominent building in the city was the Dome of Stars, a great dome which once housed the city's palantír. Osgiliath's palantír fell into the Anduin during the Kin-strife during the reign of Eldacar, Third Age 1437.
Portrayal in Adaptations
In Peter Jackson's The Two Towers, Faramir takes Frodo, Sam and Gollum to Osgiliath, where they witness a battle after which Faramir releases them to continue on to Mordor. This does not occur in the book.