We report the measurement of the anisotropic ac polarizability of ultracold polar (40)K(87)Rb molecules in the ground and first rotationally excited states. Theoretical analysis of the polarizability agrees well with experimental findings. Although the polarizability can vary by more than 30%, a "magic" angle between the laser polarization and the quantization axis is found where the polarizability of the |N=0,m(N)=0> and the |N=1,m(N)=0> states match. At this angle, rotational decoherence due to the mismatch in trapping potentials is eliminated, and we observe a sharp increase in the coherence time. This paves the way for precise spectroscopic measurements and coherent manipulations of rotational states as a tool in the creation and probing of novel quantum many-body states of polar molecules.