I did this in one of my campaigns. Fairly simple really--initially it comes off as a random encounter that turns into an ambush. The scope depends upon how much work you want to put into it.
What happened: Players arrived in a small town but had not been careful about concealing their intentions (ie, they let it be known they were going there). The town had only one inn, with barely enough rooms for the party--simple enough.
They arrived in town to find most inhabitants rather sullen, not wanting to talk much (poor interaction didn't help much). As night fell, a couple of PCs invariably left the inn--dividing their forces. That's when the fun started.
Two crossbowmen on the roof across from the inn began taking potshots at the players. Suddenly the PCs went from offense to defense. Eventually those within their room heard the commotion outside and decided to leave via the window--only to find that it, too was covered (as was the back door). The challenge for the party became how to regroup and then force their way out.
By the time they did, they found that most of their opponents had executed a rehearsed escape plan (relatively low powered--no one used teleportation, etc). But it certainly brought home the fact that the PCs were now the hunted.
The running battles that were played out lasted all night.
(Note: the "bad guys" had arrived in town early and held some of the inhabitants hostage to force cooperation from the others). Nothing more than a small gang of eight bandits with minor magic support (equivalent to a 3rd level mage)