Serbia beat Spain 7-6 on penalties after drawing 7-7 after extra time to win a men's waterpolo final at the FINA World Championships in Rome.