Section 31. Whoever, except in trials of speed of horses for premiums offered by legally constituted agricultural societies, or by corporations authorized thereto by section fourteen of chapter one hundred and eighty, engages in racing, running, trotting or pacing a horse or other animal of the horse kind for a bet, wager of money or other thing of value or a purse or stake made within the commonwealth, or whoever aids or abets therein, shall be punished by a fine of not more than one thousand dollars or by imprisonment for not more than one year, or both. This section shall not apply to racing conducted pursuant to chapter 23K.