A homeless man and his dog were stabbed in their sleep early Wednesday inside of a Manhattan subway station on one of the coldest nights of the season, police sources told The Post.

The victim, Anthony Alexander, 34, was asleep on a bench with his Rottweiler on the northbound F train platform at the 14th Street/Sixth Avenue station around 4:10 a.m. when he woke up to the vicious attack, the sources said.

The suspect, believed to be another homeless man in his 30s, stabbed Alexander in the lower left calf and the dog in one of his rear legs before fleeing the scene, police said.

The victim was taken to Bellevue Hospital in stable condition and the dog, who was brought to the city pound, is also stable, cops said.

Alexander is a regular in the area who usually sleeps on the street level but may have descended into the subway because of frigid overnight temperatures, a transit worker told The Post.

Forecasters predicted “record breaking cold air” Tuesday evening into Wednesday, prompting a “code blue” to take effect at 4 p.m. Tuesday from the Department of Homeless Services.

Code blue, which goes into effect anytime the mercury drops below 32 degrees, is put into place when dangerous temperatures make street homeless even more unsafe.

During a code blue, shelter is available citywide for anyone brought in by outreach teams, which are sent to the subways and other locations to look for homeless people and bring them to safety. Shelter is also available for walk-ins.

Additional reporting by Olivia Bensimon