Very nice compact solution.
Small improvements that can be made.
String equals are expensive task. No need to do equals of word1 and word2 in the loop. It can be computed just once and used as flag.
if (index != -1 && (word1.equals(word2) || !words[index].equals(words[i])))
//Instead below can be used
if (index != -1 && (sameWordsFlag || !words[index].equals(words[i])))
Instead of paying for so many equals, can track index of word1 and word2 separately, that will reduce the equals to just below. Of course the overall runtime remains the same and code will not be as compact as above but faster in practice for really long words.
if (words[i].equals(word1) || words[i].equals(word2))