A fan attending the Nets vs. Mavericks game on Thursday night ended up spending most of his evening in custody ... because he was arrested for throwing a cup of ice that nearly hit Luka Doncic on the court.
According to the NYPD, 24-year-old Justin Boatswain hurled the object during the middle of overtime at Barclays Center in Brooklyn ... as Kevin Durant was trying to sink some free throws.
Video from the game's broadcast shows the cup landed about six feet from the Mavericks' best player -- startling Doncic as ice splattered everywhere.
The game was halted for several minutes as officials cleaned up the mess.
Boatswain was immediately ID'ed as the cup-thrower, according to cops, and was escorted from his seat. Authorities say he was ultimately arrested and charged with a misdemeanor for interfering with a sporting event.
Doncic had some other interesting moments with fans in Brooklyn earlier in the night, too ... he was spotted jawing with some courtside attendees throughout the contest.