I had a relatively large carry-on (old-style HD tuner/DVD combo) that I had to carry onto the airplane. The flight attendants took the box and put it in a special locker. The iMac is bigger, however, and I think they will want you to check it.
Apple puts the size of the iMac at 20.8" wide and 17.7" tall. I would add a couple of inches to those dimensions and a thickness of at least 8" (the stand depth is 6.9").
Have you considered shipping the iMac to yourself instead of carrying it onto the airplane? Some people even do that for their luggage now!