Firefighters on Thursday night rescued a man from the water off the end of Custom House Wharf in Portland after he had accidentally fallen in after the end of a waterfront concert.

Members of the Portland Fire Department’s marine division were already in the waterfront area of the city’s Old Port when a friend of the man who fell ran up to them around 9:30 p.m. asking for help, Assistant Fire Chief Keith Gautreau said Friday.

While some firefighters went to nearby Maine State Pier to get a department fireboat, Deputy Chief Robert Thompson and members of an ambulance crew that had been on Commercial Street went to the end of the wharf and found the man struggling to continue treading water, Gautreau said.

The firefighters got the man to grab hold of a piling in the water until the fireboat arrived and the boat crew, Lt. John Brooks and Firefighter Charles Loring, pulled him onboard to safety, according to Gautreau.

“This could have had a much different outcome, had it not been for quick decision making of Lt. Brooks and being on the dock at the time,” Thompson, the deputy chief who helped with the rescue, said in a written statement.

Gautreau declined to identify the man who was rescued or give his age, citing patient confidentiality laws.