A Staten Island man deliberately crashed his van into the building where his ex-wife lives Sunday night — causing the vehicle to burst into flames.

Anthony Imafidon rammed his white van into Legacy African Market at 671 Bay St. in Stapleton around 11 p.m. Sunday, police said.

The 42-year-old’s ex-wife and her three children were in an upstairs apartment at the time, cops said.

Imafidon climbed out of the burning vehicle and doused it with “some sort of accelerant,” police sources said.

He was arrested and taken to Richmond University Hospital, where he was treated for injuries, police said.

Charges include attempted murder, arson and reckless endangerment of a child, cops said.

No one in the building was injured.