The stowaway made a bid for freedom when staff began undoing a tarpaulin cover on the flatbed German truck.
He dashed towards the water but MoD police tackled him and bundled him into a van.
A navy spokesman said a full investigation would be c
arried out but insisted the immigrant was not near any warships.
Citilink delivery driver Eric Ward, who was waiting behind the lorry when he saw the drama unfold, said: 'They were undoing the lorry and the geezer just jumped out and ran.
'How he got as far as the dockyards I don't know, it should have been checked before then.
'As soon as they opened the tarpaulin he was off. If he had got two more yards he would have been in the water, but the police caught him.
'They were all panicking, I have never seen so many police. It looked like they were worried there would be more about.
'He got a bit of a shock. I think he was expecting to end up in Portsmouth, not the dockyard.'
The immigrant was found just before 11am on Thursday on a lorry that had come into the country from Calais.
He was arrested and taken to Portsmouth Central Police Station before being handed over to the UK Border Agency.
A naval base spokesman said: 'We can confirm that MoD police have arrested a suspected illegal immigrant at the base.
'The naval base will be conducting an investigation into the incident.
'He was discovered trying to get out of the back of the van.'
SECURITY BREACHThe security breach comes after an illegal immigrant from Afghanistan managed to smuggle himself into Sandhurst military academy after hiding in a stairwell next to a coach toilet.
The 20-year-old hid on the Army coach when it was travelling to Britain from 28 Engineer Regiment's base at Hameln, Germany, last month.
It is thought he jumped on to the bus at Calais, where he travelled among a group of officers and NCOs who did not notice him until the coach arrived at the academy.
>> Vote in our latest web poll.