Let $S$ be a nonempty set of primes satisfying the property that for each proper subset $P$ of $S$, all the prime factors of the number $\left(\prod_{p\in P}p\right)-1$ are also in $S$. Determine all possible such sets $S$.
1. **Claim 1: \( p_1 = 2 \)**

   *Proof:* Let \( S = \{p_1, p_2, \ldots, p_n\} \) with \( p_1 < p_2 < \ldots < p_n \). Consider the subset \( P = \{p_1\} \). According to the problem's condition, there must be a prime \( p \in S \) such that \( p \mid (p_1 - 1) \). Since \( p > p_1 \), the only possibility is \( p_1 = 2 \). 

   \[
   \boxed{p_1 = 2}
   \]

2. **Claim 2: \( p_2 = 2^\alpha + 1 \) for some positive integer \(\alpha\)**

   *Proof:* Consider the subset \( P = \{p_2\} \). For all \( p > p_2 \) and \( p \in S \), \( p \nmid (p_2 - 1) \). This implies \( p_1 \mid (p_2 - 1) \). Since \( p_1 = 2 \), we have:

   \[
   p_2 = 2^\alpha + 1 \quad \text{for some positive integer } \alpha
   \]

   \[
   \boxed{p_2 = 2^\alpha + 1}
   \]

3. **Claim 3: \( p_3 = 2^{\alpha + 1} + 1 \)**

   *Proof:* Consider the subset \( P = \{p_1, p_2\} = \{2, p_2\} \). If \( p_3 > 2p_2 - 1 \), then there will be no prime in \( S \) that divides \( 2p_2 - 1 \). Therefore, \( p_3 \leq 2p_2 - 1 \). We have:

   \[
   p_2 < p_3 \leq 2p_2 - 1 \implies 2^\alpha + 1 < p_3 \leq 2^{\alpha + 1} + 1
   \]

   Since \( p_1 \) and \( p_2 \) alone must divide \( p_3 - 1 \), we have:

   \[
   p_3 = 2^a (2^\alpha + 1)^b + 1 \quad \text{for some positive integers } a, b
   \]

   If \( a = 1 \) and \( b = 1 \), then \( p_3 > 2p_2 - 1 \). Therefore, \( b = 0 \) and we have:

   \[
   2^\alpha + 1 < p_3 = 2^a + 1 \leq 2^{\alpha + 1} + 1 \implies a = \alpha + 1 \implies p_3 = 2^{\alpha + 1} + 1
   \]

   \[
   \boxed{p_3 = 2^{\alpha + 1} + 1}
   \]

4. **Fermat Primes and Further Analysis**

   Since both \( p_2 \) and \( p_3 \) are Fermat primes, we have \( \alpha = 2^m \) and \( \alpha + 1 = 2^n \). This implies:

   \[
   2^m (2^{n - m} - 1) = 1 \implies m = 0, n = 1 \implies \alpha = 1 \implies p_2 = 3, p_3 = 5
   \]

   Hence, \( S = \{2, 3, 5, p_4, p_5, \ldots, p_n\} \).

5. **Claim 4: If \( |S| \) is infinite, then \( S \) must contain all primes**

   *Proof:* Suppose \( p \) is a prime and \( p \notin S \). For some positive integer \( i \), consider the sequence:

   \[
   p_i p_{i+1} \cdots p_{i+p-1} - 1, \quad p_i p_{i+1} \cdots p_{i+p-2} - 1, \quad \ldots, \quad p_i p_{i+1} - 1, \quad p_i - 1
   \]

   Since none of these numbers is divisible by \( p \), by the Pigeonhole Principle, we must have at least two numbers with the same remainder modulo \( p \), and their difference being divisible by \( p \). This implies \( p \in S \), which is a contradiction.

   \[
   \boxed{S = \{p\}, \{2, F_n\}, \text{ or the set of all primes}}
   \]