Siege
This could be accomplished by digging a tunnel beneath the foundations of the walls, and then deliberately collapsing or exploding the tunnel. This process is known as mining. The defenders could dig counter-tunnels to cut into the attackers' works and collapse them prematurely.
Fire was often used as a weapon when dealing with wooden fortifications. The Roman Empire used Greek fire, which contained additives that made it hard to extinguish. Combined with a primitive flamethrower, it proved an effective offensive and defensive weapon. A sallying out might also occur with such weapons, or if the siege was of a location on a coastline, from ships launched from the harbor of the location.

Defensive: The universal method for defending against siege is the use of fortifications, principally walls and ditches, to supplement natural features. A sufficient supply of food and water was also important to defeat the simplest method of siege warfare: starvation. On occasion, the defenders would drive 'surplus' civilians out to reduce the demands on stored food and water.
During the Warring States period in China (481–221 BC), warfare lost its honorable, gentlemen's duty that was found in the previous era of the Spring and Autumn period, and became more practical, competitive, cut-throat, and efficient for gaining victory. The Chinese invention of the hand-held, trigger-mechanism crossbow during this period revolutionized warfare, giving greater emphasis to infantry and cavalry and less to traditional chariot warfare.
The philosophically pacifist Mohists (followers of the philosopher Mozi) of the 5th century BC believed in aiding the defensive warfare of smaller Chinese states against the hostile offensive warfare of larger domineering states. The Mohists were renowned in the smaller states (and the enemies of the larger states) for the inventions of siege machinery to scale or destroy walls. These included traction trebuchet catapults, 8-foot (2.4 m) high ballistas, a wheeled siege ramp with grappling hooks known as the Cloud Bridge (the protractible, folded ramp slinging forward by means of a counterweight with rope and pulley), and wheeled 'hook-carts' used to latch large iron hooks onto the tops of walls to pull them down.

When enemies attempted to dig tunnels under walls for mining or entry into the city, the defenders used large bellows (the type the Chinese commonly used in heating up a blast furnace for smelting cast iron) to pump smoke into the tunnels in order to suffocate the intruders.
Advances in the prosecution of sieges in ancient and medieval times naturally encouraged the development of a variety of defensive countermeasures. In particular, medieval fortifications became progressively stronger—for example, the advent of the concentric castle from the period of the Crusades—and more dangerous to attackers—witness the increasing use of machicolations and murder-holes, as well the preparation of hot or incendiary substances. Arrowslits (also called arrow loops or loopholes), sally ports (airlock-like doors) for sallies and deep water wells were also integral means of resisting siege at this time. Particular attention would be paid to defending entrances, with gates protected by drawbridges, portcullises, and barbicans. Moats and other water defenses, whether natural or augmented, were also vital to defenders.
In the European Middle Ages, virtually all large cities had city walls—Dubrovnik in Dalmatia is a well-preserved example—and more important cities had citadels, forts, or castles. Great effort was expended to ensure a good water supply inside the city in case of siege. In some cases, long tunnels were constructed to carry water into the city. Complex systems of tunnels were used for storage and communications in medieval cities like Tábor in Bohemia, similar to those used much later in Vietnam during the Vietnam War.
Until the invention of gunpowder-based weapons (and the resulting higher-velocity projectiles), the balance of power and logistics definitely favored the defender. With the invention of gunpowder, cannon and mortars and howitzers (in modern times), the traditional methods of defense became less effective against a determined siege.

Siege accounts: Although there are numerous ancient accounts of cities being sacked, few contain any clues to how this was achieved. Some popular tales existed on how the cunning heroes succeeded in their sieges. The best-known is the Trojan Horse of the Trojan War, and a similar story tells how the Canaanite city of Joppa was conquered by the Egyptians in the 15th century BC. The Biblical Book of Joshua contains the story of the miraculous Battle of Jericho.
A more detailed historical account from the 8th century BC, called the Piankhi stela, records how the Nubians laid siege to and conquered several Egyptian cities by using battering rams, archers, and slingers and building causeways across moats.

Classical antiquity: During the Peloponnesian War, one hundred sieges were attempted and fifty-eight ended with the surrender of the besieged area.
Alexander the Great's army successfully besieged many powerful cities during his conquests. Two of his most impressive achievements in siegecraft took place in the Siege of Tyre and the Siege of the Sogdian Rock. His engineers built a causeway that was originally 60 m (200 ft) wide and reached the range of his torsion-powered artillery, while his soldiers pushed siege towers housing stone throwers and light catapults to bombard the city walls.
Most conquerors before him had found Tyre, a Phoenician island-city about 1 km (1,100 yd) from the mainland, impregnable. The Macedonians built a mole, a raised spit of earth across the water, by piling stones up on a natural land bridge that extended underwater to the island, and although the Tyrians rallied by sending a fire ship to destroy the towers, and captured the mole in a swarming frenzy, the city eventually fell to the Macedonians after a seven-month siege. In complete contrast to Tyre, Sogdian Rock was captured by stealthy attack. Alexander used commando-like tactics to scale the cliffs and capture the high ground, and the demoralized defenders surrendered.

The importance of siege warfare in the ancient period should not be underestimated. One of the contributing causes of Hannibal's inability to defeat Rome was his lack of siege engines, thus, while he was able to defeat Roman armies in the field, he was unable to capture Rome itself. The legionary armies of the Roman Republic and Empire are noted as being particularly skilled and determined in siege warfare. An astonishing number and variety of sieges, for example, formed the core of Julius Caesar's mid-1st-century BC conquest of Gaul (modern France).
In his Commentarii de Bello Gallico (Commentaries on the Gallic War), Caesar describes how, at the Battle of Alesia, the Roman legions created two huge fortified walls around the city. The inner circumvallation, 16 km (10 mi), held in Vercingetorix's forces, while the outer contravallation kept relief from reaching them. The Romans held the ground in between the two walls. The besieged Gauls, facing starvation, eventually surrendered after their relief force met defeat against Caesar's auxiliary cavalry.
The Sicarii Zealots who defended Masada in AD 73 were defeated by the Roman legions, who built a ramp 100 metres (330 ft) high up to the fortress's west wall.
During the Roman–Persian Wars, siege warfare was extensively being used by both sides.

Medieval period: 

Mongols and Chinese: In the Middle Ages, the Mongol Empire's campaign against China (then comprising the Western Xia dynasty, Jin dynasty, and Southern Song dynasty) by Genghis Khan until Kublai Khan, who eventually established the Yuan dynasty in 1271, was very effective, allowing the Mongols to sweep through large areas. Even if they could not enter some of the more well-fortified cities, they used innovative battle tactics to grab hold of the land and the people:

By concentrating on the field armies, the strongholds had to wait. Of course, smaller fortresses, or ones easily surprised, were taken as they came along. This had two effects. First, it cut off the principal city from communicating with other cities where they might expect aid. Secondly, refugees from these smaller cities would flee to the last stronghold. The reports from these cities and the streaming hordes of refugees not only reduced the morale of the inhabitants and garrison of the principal city, it also strained their resources. Food and water reserves were taxed by the sudden influx of refugees. Soon, what was once a formidable undertaking became easy. The Mongols were then free to lay siege without interference of the field army, as it had been destroyed. At the siege of Aleppo, Hulagu used twenty catapults against the Bab al-Iraq (Gate of Iraq) alone. 
In Jûzjânî, there are several episodes in which the Mongols constructed hundreds of siege machines in order to surpass the number which the defending city possessed. While Jûzjânî surely exaggerated, the improbably high numbers which he used for both the Mongols and the defenders do give one a sense of the large numbers of machines used at a single siege.
Another Mongol tactic was to use catapults to launch corpses of plague victims into besieged cities.