Let the number of sides be n and use the formula: 1/2n(n-3) = diagonals 

1/2n(n-3) = 27 

Multiply both sides by 2 and then form a quadratic equation: 

n2-3n-54 = 0 

Solving the above quadratic equation works out as: 

n = -6 or n = 9 it must be the latter because the sides can't be negative 

Therefore the polygon has 9 sides.