The siege of Zama (109 BC) was a Roman attempt to force Jugurtha to accept battle that backfired and had to be abandoned after Jugurtha carried out a series of costly attacks on the Roman camp (Jugurthine War).
Quintus Caecilius Metellus, one of the consuls for 109, had taken Numidia as his province. After restoring discipline in the Roman army he had invaded eastern Numidia, captured the wealthy city of Vaga and then moved south towards the heart of the kingdom. At first Jugurtha had attempted to negotiation with Metellus, but he eventually realised that this wasn't an option, and decided to try and ambush the Romans on the Muthul River. This battle began well for the Numidians, but the Roman army didn't break, and eventually the Numidians were forced to retreat. Most of Jugurtha's more experienced men are said to have deserted after this setback, forcing him to raise a fresh army.
Metellus then split his army into two, one column commanded by himself and the other under his legate Gaius Marius. The two armies carried out a raid across the wealthiest parts of Numidia, burning and plundering. Jugurtha harassed the two Roman columns, but never risked a large scale battle. Eventually Metellus lost patience with this approach, and instead decided to besiege the city of Zama, in the eastern part of the kingdom, in the hope that this would force Jugurtha to risk a battle.
Jugurtha was given advance warning of this plan by some Roman deserters. He managed to get to Zama ahead of the Romans, placed a group of Roman deserters in the garrison, in the knowledge that they couldn't afford to surrender, encouraged the citizens to defend the city, and then retreated into the nearby deserts to watch events unfold.
His first chance for a quick victory came during the Roman march towards Zama. Marius, with a small detachment of a few cohorts, had been sent to Sicca, a town that had swapped sides after the battle of the Muthul River, to gather supplies. Jugurtha attacked Marius just as they were leaving the gates of the town, while at the same time calling on the locals to attack the Romans from the rear. Marius moved too quickly for this to happen, ordering his men to advance out of the town to attack Jugurtha's men. After a short fight the Numidians fled, without suffering many casualties. Marius then joined Metellus outside Zama.
Sallust describes a rather chaotic Roman siege. Metellus had his men surround the city, and then everyone was allowed to act according to their inclinations, with some attacking with slings and others attempting to undermine or scale the walls. This sounds rather unlikely, and perhaps just suggests that Metellus carried out a wide range of siege activities. The defenders carried out an active defence, inflicting casualties on the Romans.
While the Romans were attacking the city, Jugurtha attacked their camp. Metellus had left troops to guard the camp, but they weren't expected an attack, and the Numidians were able to break in through one of the gates. About forty Romans managed to make a stand on some higher ground within the camp, and were able to fight off any attacks on them (in all likelihood Jugurtha's men found looting the undefended parts of the camp more promising than attacking the one area of real resistance). Metellus realised the camp was under attack after hearing the sounds of battle from his rear and seeing some of his troops fleeing towards the main army. He sent all of his cavalry, and then Marius with the Allied cohorts to save the camp. Jugurtha suffered some losses while trying to disengage, with some getting stuck at the gates and others fleeing over the walls. Metellus then returned to the camp with his main army, having failed to capture the city.
On the following day Metellus made more efforts to protect his camp, leaving all of his cavalry to guard the side from where Jugurtha had attacked on the previous day, and leaving a tribune in charge of each gate. He then led his infantry back to Zama to renew the siege.
Once again Jugurtha attacked the camp, mixing his cavalry and infantry to attack the Roman cavalry. This combined assault came close to success, but on this occasion Metellus doesn't appear to have had to send reinforcements from Zama.
Once again the fighting at Zama is described as rather chaotic, with heavy fighting all around. However the defenders were also distracted by the battle at the camp, which was visible from the walls. Marius attempted to take advantage of this, by ordering his men to relax their efforts until the defenders on their front were concentrating purely on the distant battle. He then ordered his men to try another assault. They were almost at the top of their scaling ladders when the defenders realised what was going on and threw back Marius's men with heavy losses.
The failure of the two days of assaults, and the two attacks on his camp, combined with the approach of winter, convinced Metallus to abandon the siege. He pulled back into winter quarters, leaving garrisons in those cities that had changed sides, while the main Roman army withdrew into the Roman province of Africa. He spent the winter attempting to undermine Jugurtha through treachery, but without success.