xmodmap

The 'shift, lock, control, modN' on the left are what X sees and cares about. The keysyms on the right map to them. Mode_switch is your AltGr key. Move it to join the others at mod1:

xmodmap -e 'clear mod5'
xmodmap -e 'add mod1 = Mode_switch'

gnome-tweak-tool lets you do this with a GUI:

Typing -> Key to choose 3rd level -> Right Alt key never chooses 3rd level


For those UK users still pulling their hairs out, this worked for me:

xmodmap -e "clear mod5"
xmodmap -e "keycode 108 = Alt_L"

Explanation: The first line removes the current behaviour of your AltGr (which is assigned to the mod5 modifier). The second takes the AltGr key (which on my keyboard produces a keycode of 108), and maps that to whatever keycode your Alt_L key is mapped to.

If you have no idea what is going on with keycodes and keysyms, I found this xmodmap introduction very useful.