Soldiers and a fighter jet were used in a counter-attack after Islamist fighters overran a checkpoint on the edge of the city.
The insurgents were retreating towards their stronghold in the neighbouring state of Borno, witnesses said.
Nigeria postponed elections due to be held on Saturday due to the insurgency in the north-east.
Before they left, the militants scattered leaflets urging people not to vote in the elections.
All roads in and out of Gombe have been blocked and a 24-hour curfew imposed, reports the BBC’s Abdullahi Kaura Abubakar in Abuja.
Gombe – capital of Gombe State – has previously suffered suicide attacks but correspondents say this was the first time Boko Haram launched a direct assault on the city.
Reports said militants first attacked the town of Dadin Kowa, about 40km (25 miles) from Gombe.
Ground troops with air support then battled to keep the insurgents from entering the city, as residents fled into the bush and nearby hills.
Boko Haram controls a swathe of territory in north-eastern Nigeria.
Its insurgency has become a regional crisis with the four affected countries – Nigeria, Niger, Chad and Cameroon -agreeing to form a regional military force to try to contain the threat.
In response, the insurgents have stepped up their attacks in Nigeria and neighbouring states.
It emerged on Friday that Boko Haram had attacked Chad for the first time, crossing Lake Chad in four motorboats and raiding a village overnight.
Security sources and witnesses said five people were killed by Boko Haram in the village of Ngouboua, including a local chief, a police officer and three civilians. The Chadian military said two of the attackers were also killed.
Some reports put the civilian death toll higher.
The BBC’s Tomi Oladipo hears the harrowing stories of refugees from Boko Haram living in north-eastern Nigeria
Villagers said about 30 militants took part in the attack, setting fire to two-thirds of homes.
Boko Haram, which wants to create an Islamic caliphate in Nigeria, has killed thousands and forced millions to flee their homes in north-east Nigeria since 2009.
Story and picture provided courtesy of www,bbcafrica,com