A man was rescued after falling into the Potomac River near Great Falls while trying to take a selfie Sunday evening, officials said.

WASHINGTON — A dangerous selfie nearly cost a man his life after he accidentally slipped into the raging Potomac River Sunday evening on the Maryland side of Great Falls.

A number of bystanders had to pull the man out of the river, which is at a high level and moving violently due to recent heavy rains.

“The floodwaters are moving very quickly,” said Montgomery County Fire and Rescue Service spokesman Pete Piringer. “It is a dangerous environment.”

Flood warnings were in effect for the areas around the Potomac River in Loudoun County, Virginia, and Montgomery County, Maryland until 10 p.m. Sunday night. Many of the park trails are closed due to the high tides as well.

According to Piringer, the man tried to snap a picture of himself near the water when he slipped and fell in.

Lucky for him, several people were nearby to help immediately.

“Some passersby were able to retrieve the man from the water,” Piringer said. “We believe that their actions were likely lifesaving in this case.”

Rescue teams from the fire department responded to the scene near Olmstead Island around 5:30 p.m. to treat the man and take him to the hospital.

The man had serious injuries but he is expected to recover.

“U.S. Park Police and the park rangers are investigating the circumstances,” said Piringer.

The National Park Service has closed several areas along the Potomac River due to high water and “hazardous conditions.”

WTOP’s Nahal Amouzadeh and Andrea Cambron contributed to this report.