ALMOST GOT AWAY: Miguel Mejias-Ramos, here after his arrest Monday night, was hours away from disappearing across the Mexican border, where he was fleeing after the Queens murders of his wife, Deisy, and daughters Danielle, 3, and Yoselin, 1 (inset).

The fugitive dad suspected of slaughtering his wife and two adorable daughters in Queens was arrested in Texas — where he was just hours away from the Mexican border, authorities said.

Miguel Mejias-Ramos was fleeing in his white van when he was stopped by a team of US marshals and Texas state troopers in Schulenburg, Texas, before he could cross into Mexico, where it would have been nearly impossible to find him, authorities said.

“Fortunately, we got him before he made his way across the border to Mexico,” said a source. “If we hadn’t, it would have taken a long time — several years — to get him back to the United States, and he could have disappeared and gotten away with it.”

Mejias-Ramos has been on the lam since Sunday, when he allegedly butchered his 21-year-old wife, Deisy Garcia, and their two little girls, Danielle, 3, and Yoselin, 1, inside their South Jamaica home.

Authorities were able to zero in on the killer by tracking his cellphone, which he apparently used several times to call contacts in Mexico during his frenzied drive from New York to Texas.

Once authorities had a general location on Mejias-Ramos, 28, a task force of US marshals and local authorities in Texas fanned out and began searching for his vehicle, sources said.

Authorities eventually spotted the van with New York plates, which was registered to Mejias-Ramos, and used a roadblock to stop him at around 10 p.m. Monday, according to Fayette County Sheriff Keith Koronek.

At the time of his arrest, Mejias-Ramos had what appeared to be self-inflicted stab wounds on his neck, believed to have been made with a plastic utensil, sources said.

Mejias-Ramos was being held Tuesday in La Grange, Texas, where he was waiting to go before a judge to be charged with the heinous crime.

He will then be interviewed by NYPD officers, who are expected to arrive in Texas sometime Wednesday, sources said, at which point he will be brought back to New York.

Garcia’s uncle found the slaughtered family Sunday night in the Sutphin Avenue apartment.

The young mom was found on the floor of one bedroom, while the girls’ bodies were on a bed in another room.

All three victims had been stabbed multiple times, and bloody knives were left by the victims’ sides, law-enforcement sources said.