We're told Bieber has just been released by Custom's officials ... after 5-hours of heavy grilling.
was flagged by U.S. Customs officials when he landed in New Jersey this afternoon because he has 2 pending criminal cases ... law enforcement sources tell TMZ.
Bieber is still being grilled by Customs people ... after they searched his plane because they allegedly smelled weed. The search turned up nothing.
We're told -- as a result of the Patriot Act -- Customs officials have broad power to flag people coming in from another country when they have an active criminal case or a conviction. Justin currently has an assault case in Canada and a DUI case in Miami Beach.
Sources say Bieber is being "put through the grinder" right now by Customs folks. As one source said, "Once you're flagged it's a grueling process to get in the country."
It's almost certain Justin will eventually be cleared to leave Teterboro Airport because both alleged offenses are minor.
As we first reported ... Justin flew there for the Super Bowl.