A Barcelona city spokeswoman said nobody was injured in the accident, and the city's firefighters announced in a tweet that the fire had been put out hours after the ship crashed.
The spokeswoman, who wasn't authorized to be identified by name in media reports, said a dozen firefighting vehicles and several ambulances had been dispatched to the port.
She said the flames coming from four containers that fell from the ship were tackled with foam because some of them contained hazardous chemicals.
The civil protection department also activated an alert for possible sea pollution.
Grandi Navi Veloci, the Italian company that owns the ferry, said in a statement that strong winds and sea currents prevented the ship from docking, eventually pushing it against the port's crane.
The ferry, which is 200 meters (650 feet) long was carrying passengers and vehicles, GNV said, adding that nobody was injured.