Firefighters from Andover and North Andover joined crews from across the Merrimack Valley on Sunday afternoon as a five-alarm fire tore through three apartment buildings in Lawrence, displacing more than 50 residents and prompting a dramatic ladder rescue.

The fire broke out around 12:45 p.m. at the corner of Haverhill and Margin streets, drawing dozens of firefighters under the region's mutual aid system.

One of the most dramatic moments came when firefighters spotted a man trapped on a third-floor window ledge, surrounded by heavy smoke.

"He had smoke coming out all around him, he was waving for help," Lawrence Fire Chief Patrick Delaney told WBZ-TV. "Our crews did a great job getting a ladder up to him. One of our members went up there and assisted him down the ladder. It's a very heroic thing."

The man was rescued by ladder and taken to a local hospital. Fire officials have not released an update on his condition.

The fast-moving blaze heavily damaged all three multi-family homes, leaving more than 50 people without a place to live. Officials said residents will not be able to return because of the extent of the damage.

Smoke from the fire could be seen from Interstate 495 and across the Merrimack River as crews worked for hours to bring the blaze under control. Utility service was shut off in the area, and nearby roads were closed while firefighters battled the fire.

The cause remains under investigation.

Andover and North Andover were among several communities that responded to assist Lawrence through the Merrimack Valley mutual aid system, helping crews contain one of the city's largest fires this summer.